|
| 1 | +<script setup lang="ts"> |
| 2 | +import { joinURL } from 'ufo' |
| 3 | +import { kebabCase } from 'scule' |
| 4 | +
|
| 5 | +definePageMeta({ |
| 6 | + layout: 'docs', |
| 7 | +}) |
| 8 | +
|
| 9 | +const appConfig = useAppConfig() |
| 10 | +const route = useRoute() |
| 11 | +
|
| 12 | +const { data: page } = await useAsyncData(kebabCase(route.path), () => |
| 13 | + queryCollection('examples').path(`${route.path}/readme`).first(), |
| 14 | +) |
| 15 | +if (!page.value) { |
| 16 | + throw createError({ |
| 17 | + statusCode: 404, |
| 18 | + statusMessage: 'Example not found', |
| 19 | + message: `${route.path} does not exist`, |
| 20 | + fatal: true, |
| 21 | + }) |
| 22 | +} |
| 23 | +
|
| 24 | +const { data: surround } = await useAsyncData(`${kebabCase(route.path)}-surround`, async () => { |
| 25 | + const data = await queryCollectionItemSurroundings('examples', `${route.path}/readme`, { |
| 26 | + fields: ['description'], |
| 27 | + }).where('category', '=', page.value?.category) |
| 28 | +
|
| 29 | + return data?.map((item) => { |
| 30 | + if (!item) return null |
| 31 | + return { ...item, path: item.path?.replace('/readme', '') } |
| 32 | + }) |
| 33 | +}) |
| 34 | +
|
| 35 | +// Extract example name from route (e.g., "/examples/vite-ssr-html" -> "vite-ssr-html") |
| 36 | +const exampleName = computed(() => { |
| 37 | + return route.path.replace(/^\/examples\//, '') |
| 38 | +}) |
| 39 | +
|
| 40 | +const breadcrumb = computed(() => [ |
| 41 | + { label: 'Examples', icon: 'i-lucide-folder-code', to: '/examples' }, |
| 42 | + { label: page.value?.title || exampleName.value }, |
| 43 | +]) |
| 44 | +
|
| 45 | +const path = computed(() => route.path.replace(/\/$/, '')) |
| 46 | +prerenderRoutes([joinURL('/raw', `${path.value}.md`)]) |
| 47 | +useHead({ |
| 48 | + link: [ |
| 49 | + { |
| 50 | + rel: 'alternate', |
| 51 | + href: joinURL(appConfig.site.url, 'raw', `${path.value}.md`), |
| 52 | + type: 'text/markdown', |
| 53 | + }, |
| 54 | + ], |
| 55 | +}) |
| 56 | +</script> |
| 57 | + |
| 58 | +<template> |
| 59 | + <UPage v-if="page"> |
| 60 | + <UPageHeader |
| 61 | + :title="page.title" |
| 62 | + :description="page.description" |
| 63 | + :ui="{ |
| 64 | + wrapper: 'flex-row items-center flex-wrap justify-between', |
| 65 | + }" |
| 66 | + > |
| 67 | + <template #headline> |
| 68 | + <UBreadcrumb :items="breadcrumb" /> |
| 69 | + </template> |
| 70 | + <template #links> |
| 71 | + <UButton |
| 72 | + icon="i-simple-icons-stackblitz" |
| 73 | + label="Open in Playground" |
| 74 | + color="neutral" |
| 75 | + variant="soft" |
| 76 | + size="sm" |
| 77 | + :to="`https://stackblitz.com/fork/github/${appConfig.docs?.github}/tree/${appConfig.docs?.branch || 'main'}/examples/${exampleName}`" |
| 78 | + target="_blank" |
| 79 | + /> |
| 80 | + |
| 81 | + <UButton |
| 82 | + icon="i-simple-icons-github" |
| 83 | + label="Source" |
| 84 | + color="neutral" |
| 85 | + variant="soft" |
| 86 | + size="sm" |
| 87 | + :to="`https://github.com/${appConfig.docs?.github}/tree/${appConfig.docs?.branch || 'main'}/examples/${exampleName}`" |
| 88 | + target="_blank" |
| 89 | + /> |
| 90 | + |
| 91 | + <PageHeaderLinks /> |
| 92 | + </template> |
| 93 | + </UPageHeader> |
| 94 | + |
| 95 | + <template |
| 96 | + v-if="page.body?.toc?.links?.length" |
| 97 | + #right |
| 98 | + > |
| 99 | + <UContentToc |
| 100 | + title="On this page" |
| 101 | + :links="page.body?.toc?.links || []" |
| 102 | + highlight |
| 103 | + /> |
| 104 | + </template> |
| 105 | + |
| 106 | + <UPageBody |
| 107 | + prose |
| 108 | + class="break-words" |
| 109 | + > |
| 110 | + <ContentRenderer |
| 111 | + v-if="page.body" |
| 112 | + :value="page" |
| 113 | + /> |
| 114 | + |
| 115 | + <div class="space-y-6"> |
| 116 | + <USeparator type="dashed" /> |
| 117 | + <div class="mb-4"> |
| 118 | + <UPageLinks |
| 119 | + class="inline-block" |
| 120 | + :links="[ |
| 121 | + { |
| 122 | + icon: 'i-lucide-pencil', |
| 123 | + label: 'Edit this page', |
| 124 | + to: `https://github.com/${appConfig.docs?.github}/edit/${appConfig.docs?.branch || 'main'}/examples/${exampleName}/README.md`, |
| 125 | + target: '_blank', |
| 126 | + }, |
| 127 | + ]" |
| 128 | + /> |
| 129 | + </div> |
| 130 | + <UContentSurround |
| 131 | + v-if="surround?.length" |
| 132 | + class="mb-4" |
| 133 | + :surround="surround" |
| 134 | + /> |
| 135 | + </div> |
| 136 | + </UPageBody> |
| 137 | + </UPage> |
| 138 | +</template> |
0 commit comments