Skip to content

Commit 9172bb7

Browse files
authored
docs(app): add copy markdown button (#4369)
1 parent 32dae2e commit 9172bb7

File tree

5 files changed

+520
-406
lines changed

5 files changed

+520
-406
lines changed
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<script setup lang="ts">
2+
const route = useRoute()
3+
const toast = useToast()
4+
const { copy, copied } = useClipboard()
5+
const site = useSiteConfig()
6+
7+
const mdPath = computed(() => `${site.url}/raw${route.path}.md`)
8+
9+
const items = [
10+
{
11+
label: 'Copy Markdown link',
12+
icon: 'i-lucide-link',
13+
onSelect() {
14+
copy(mdPath.value)
15+
toast.add({
16+
title: 'Copied to clipboard',
17+
icon: 'i-lucide-check-circle'
18+
})
19+
}
20+
},
21+
{
22+
label: 'View as Markdown',
23+
icon: 'i-simple-icons:markdown',
24+
target: '_blank',
25+
to: `/raw${route.path}.md`
26+
},
27+
{
28+
label: 'Open in ChatGPT',
29+
icon: 'i-simple-icons:openai',
30+
target: '_blank',
31+
to: `https://chatgpt.com/?hints=search&q=${encodeURIComponent(`Read ${mdPath.value} so I can ask questions about it.`)}`
32+
},
33+
{
34+
label: 'Open in Claude',
35+
icon: 'i-simple-icons:anthropic',
36+
target: '_blank',
37+
to: `https://claude.ai/new?q=${encodeURIComponent(`Read ${mdPath.value} so I can ask questions about it.`)}`
38+
}
39+
]
40+
41+
async function copyPage() {
42+
copy(await $fetch<string>(`/raw${route.path}.md`))
43+
}
44+
</script>
45+
46+
<template>
47+
<UButtonGroup>
48+
<UButton
49+
label="Copy page"
50+
:icon="copied ? 'i-lucide-copy-check' : 'i-lucide-copy'"
51+
color="neutral"
52+
variant="outline"
53+
:ui="{
54+
leadingIcon: [copied ? 'text-primary' : 'text-neutral', 'size-3.5']
55+
}"
56+
@click="copyPage"
57+
/>
58+
<UDropdownMenu
59+
:items="items"
60+
:content="{
61+
align: 'end',
62+
side: 'bottom',
63+
sideOffset: 8
64+
}"
65+
:ui="{
66+
content: 'w-48'
67+
}"
68+
>
69+
<UButton
70+
icon="i-lucide-chevron-down"
71+
size="sm"
72+
color="neutral"
73+
variant="outline"
74+
/>
75+
</UDropdownMenu>
76+
</UButtonGroup>
77+
</template>

docs/app/pages/[...slug].vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ const communityLinks = computed(() => [{
141141
<MDC v-if="page.description" :value="page.description" unwrap="p" :cache-key="`${kebabCase(route.path)}-description`" />
142142
</template>
143143

144-
<template v-if="page.links?.length" #links>
144+
<template #links>
145145
<UButton
146146
v-for="link in page.links"
147147
:key="link.label"
@@ -154,6 +154,7 @@ const communityLinks = computed(() => [{
154154
<UAvatar v-bind="link.avatar" size="2xs" :alt="`${link.label} avatar`" />
155155
</template>
156156
</UButton>
157+
<PageHeaderLinks />
157158
</template>
158159
</UPageHeader>
159160

0 commit comments

Comments
 (0)