|
| 1 | +<script setup lang="ts"> |
| 2 | +import { useClipboard } from '@vueuse/core' |
| 3 | +import { withTrailingSlash } from 'ufo' |
| 4 | +
|
| 5 | +const route = useRoute() |
| 6 | +const runtimeConfig = useRuntimeConfig() |
| 7 | +const appBaseURL = runtimeConfig.app?.baseURL || '/' |
| 8 | +
|
| 9 | +const { copy, copied } = useClipboard() |
| 10 | +const { t } = useDocusI18n() |
| 11 | +
|
| 12 | +const markdownLink = computed(() => `${window?.location?.origin}${withTrailingSlash(appBaseURL)}raw${route.path}.md`) |
| 13 | +const items = computed(() => [ |
| 14 | + [{ |
| 15 | + label: t('docs.copy.link'), |
| 16 | + icon: 'i-lucide-link', |
| 17 | + onSelect() { |
| 18 | + copy(markdownLink.value) |
| 19 | + }, |
| 20 | + }, |
| 21 | + { |
| 22 | + label: t('docs.copy.view'), |
| 23 | + icon: 'i-simple-icons:markdown', |
| 24 | + target: '_blank', |
| 25 | + to: markdownLink.value, |
| 26 | + }, |
| 27 | + { |
| 28 | + label: t('docs.copy.gpt'), |
| 29 | + icon: 'i-simple-icons:openai', |
| 30 | + target: '_blank', |
| 31 | + to: `https://chatgpt.com/?hints=search&q=${encodeURIComponent(`Read ${markdownLink.value} so I can ask questions about it.`)}`, |
| 32 | + }, |
| 33 | + { |
| 34 | + label: t('docs.copy.claude'), |
| 35 | + icon: 'i-simple-icons:anthropic', |
| 36 | + target: '_blank', |
| 37 | + to: `https://claude.ai/new?q=${encodeURIComponent(`Read ${markdownLink.value} so I can ask questions about it.`)}`, |
| 38 | + }], |
| 39 | +]) |
| 40 | +
|
| 41 | +async function copyPage() { |
| 42 | + const page = await $fetch<string>(`/raw${route.path}.md`) |
| 43 | + copy(page) |
| 44 | +} |
| 45 | +</script> |
| 46 | + |
| 47 | +<template> |
| 48 | + <UFieldGroup size="sm"> |
| 49 | + <UButton |
| 50 | + :label="t('docs.copy.page')" |
| 51 | + :icon="copied ? 'i-lucide-check' : 'i-lucide-copy'" |
| 52 | + color="neutral" |
| 53 | + variant="soft" |
| 54 | + :ui="{ |
| 55 | + leadingIcon: 'text-neutral size-3.5', |
| 56 | + }" |
| 57 | + @click="copyPage" |
| 58 | + /> |
| 59 | + |
| 60 | + <UDropdownMenu |
| 61 | + size="sm" |
| 62 | + :items="items" |
| 63 | + :content="{ |
| 64 | + align: 'end', |
| 65 | + side: 'bottom', |
| 66 | + sideOffset: 8, |
| 67 | + }" |
| 68 | + > |
| 69 | + <UButton |
| 70 | + icon="i-lucide-chevron-down" |
| 71 | + color="neutral" |
| 72 | + variant="soft" |
| 73 | + class="border-l border-muted" |
| 74 | + /> |
| 75 | + </UDropdownMenu> |
| 76 | + </UFieldGroup> |
| 77 | +</template> |
0 commit comments