docs: make generate work

This commit is contained in:
Benjamin Canac
2024-09-24 17:53:21 +02:00
parent d921b764de
commit b7f9422091
10 changed files with 41 additions and 28 deletions

View File

@@ -9,7 +9,7 @@ const runtimeConfig = useRuntimeConfig()
const { integrity, api } = runtimeConfig.public.content const { integrity, api } = runtimeConfig.public.content
const { data: navigation } = await useAsyncData('navigation', () => fetchContentNavigation(), { default: () => [] }) const { data: navigation } = await useAsyncData('navigation', () => fetchContentNavigation(), { default: () => [] })
const { data: files } = await useLazyFetch<any[]>(`${api.baseURL}/search${integrity ? '.' + integrity : ''}`, { default: () => [] }) const { data: files } = await useLazyFetch<any[]>(`${api.baseURL}/search${integrity ? '-' + integrity : ''}`, { default: () => [] })
const searchTerm = ref('') const searchTerm = ref('')
@@ -71,24 +71,29 @@ useServerSeoMeta({
}) })
provide('navigation', navigation) provide('navigation', navigation)
provide('files', files)
</script> </script>
<template> <template>
<UApp> <UApp>
<NuxtLoadingIndicator /> <NuxtLoadingIndicator />
<Banner v-if="!route.path.startsWith('/examples')" /> <template v-if="!route.path.startsWith('/examples')">
<Banner />
<Header v-if="!route.path.startsWith('/examples')" :links="links" /> <Header :links="links" />
</template>
<NuxtLayout> <NuxtLayout>
<NuxtPage /> <NuxtPage />
</NuxtLayout> </NuxtLayout>
<Footer v-if="!route.path.startsWith('/examples')" /> <template v-if="!route.path.startsWith('/examples')">
<Footer />
<LazyUContentSearch v-model:search-term="searchTerm" :files="files" :navigation="navigation" :fuse="{ resultLimit: 42 }" /> <ClientOnly>
<LazyUContentSearch v-model:search-term="searchTerm" :files="files" :navigation="navigation" :fuse="{ resultLimit: 42 }" />
</ClientOnly>
</template>
</UApp> </UApp>
</template> </template>

View File

@@ -2,6 +2,7 @@
<script setup lang="ts"> <script setup lang="ts">
import json5 from 'json5' import json5 from 'json5'
import { upperFirst, camelCase, kebabCase } from 'scule' import { upperFirst, camelCase, kebabCase } from 'scule'
import { hash } from 'ohash'
import * as theme from '#build/ui' import * as theme from '#build/ui'
import { get, set } from '#ui/utils' import { get, set } from '#ui/utils'
@@ -179,7 +180,7 @@ const code = computed(() => {
return code return code
}) })
const { data: ast } = await useAsyncData(`component-code-${name}-${JSON.stringify({ props: componentProps, slots: props.slots })}`, async () => { const { data: ast } = await useAsyncData(`component-code-${name}-${hash({ props: componentProps, slots: props.slots })}`, async () => {
if (!props.prettier) { if (!props.prettier) {
return parseMarkdown(code.value) return parseMarkdown(code.value)
} }

View File

@@ -22,7 +22,7 @@ const meta = await fetchComponentMeta(name as any)
</ProseTr> </ProseTr>
</ProseThead> </ProseThead>
<ProseTbody> <ProseTbody>
<ProseTr v-for="event in meta.meta.events" :key="event.name"> <ProseTr v-for="event in (meta?.meta?.events || [])" :key="event.name">
<ProseTd> <ProseTd>
<ProseCodeInline> <ProseCodeInline>
{{ event.name }} {{ event.name }}

View File

@@ -22,7 +22,7 @@ const meta = await fetchComponentMeta(name as any)
</ProseTr> </ProseTr>
</ProseThead> </ProseThead>
<ProseTbody> <ProseTbody>
<ProseTr v-for="slot in meta.meta.slots" :key="slot.name"> <ProseTr v-for="slot in (meta?.meta?.slots || [])" :key="slot.name">
<ProseTd> <ProseTd>
<ProseCodeInline> <ProseCodeInline>
{{ slot.name }} {{ slot.name }}

View File

@@ -9,8 +9,8 @@ const name = camelCase(route.params.slug?.[route.params.slug.length - 1] ?? '')
const strippedCompoundVariants = ref(false) const strippedCompoundVariants = ref(false)
function stripCompoundVariants(component: any) { function stripCompoundVariants(component?: any) {
if (component.compoundVariants) { if (component?.compoundVariants) {
component.compoundVariants = component.compoundVariants.filter((compoundVariant: any) => { component.compoundVariants = component.compoundVariants.filter((compoundVariant: any) => {
if (compoundVariant.color) { if (compoundVariant.color) {
if (!['primary', 'gray'].includes(compoundVariant.color)) { if (!['primary', 'gray'].includes(compoundVariant.color)) {

View File

@@ -1,4 +1,6 @@
<script setup lang="ts"> <script setup lang="ts">
import { murmurHash } from 'ohash'
const props = defineProps<{ const props = defineProps<{
type: string type: string
}>() }>()
@@ -21,7 +23,7 @@ const type = computed(() => {
return type return type
}) })
const { data: ast } = await useAsyncData(`hightlight-inline-code-${type.value}`, () => parseMarkdown(`\`${type.value}\`{lang="ts-type"}`)) const { data: ast } = await useAsyncData(`hightlight-inline-code-${murmurHash(type.value)}`, () => parseMarkdown(`\`${type.value}\`{lang="ts-type"}`))
</script> </script>
<template> <template>

View File

@@ -79,7 +79,7 @@ defineOgImageComponent('Docs', {
<template> <template>
<UPage v-if="page"> <UPage v-if="page">
<UPageHeader :title="page.title" :links="page.links" :headline="headline" :ui="{}"> <UPageHeader :title="page.title" :links="page.links" :headline="headline">
<template #description> <template #description>
<MDC v-if="page.description" :value="page.description" unwrap="p" /> <MDC v-if="page.description" :value="page.description" unwrap="p" />
</template> </template>
@@ -90,7 +90,7 @@ defineOgImageComponent('Docs', {
<USeparator /> <USeparator />
<UContentSurround :surround="surround as any" /> <UContentSurround :surround="(surround as any)" />
</UPageBody> </UPageBody>
<template v-if="page?.body?.toc?.links?.length" #right> <template v-if="page?.body?.toc?.links?.length" #right>

View File

@@ -15,7 +15,7 @@ navigation:
## Examples ## Examples
## API <!-- ## API
### Props ### Props
@@ -31,4 +31,4 @@ navigation:
## Theme ## Theme
:component-theme :component-theme -->

View File

@@ -15,7 +15,7 @@ navigation:
## Examples ## Examples
## API <!-- ## API
### Props ### Props
@@ -31,4 +31,4 @@ navigation:
## Theme ## Theme
:component-theme :component-theme -->

View File

@@ -31,6 +31,10 @@ export default defineNuxtConfig({
compatibilityVersion: 4 compatibilityVersion: 4
}, },
experimental: {
buildCache: true
},
runtimeConfig: { runtimeConfig: {
public: { public: {
version: pkg.version version: pkg.version
@@ -72,16 +76,17 @@ export default defineNuxtConfig({
provider: 'ipx' provider: 'ipx'
}, },
// nitro: { nitro: {
// prerender: { prerender: {
// routes: [ routes: [
// '/getting-started' '/getting-started'
// // '/api/releases.json', // '/api/releases.json',
// // '/api/pulls.json' // '/api/pulls.json'
// ], ],
// ignore: !process.env.NUXT_GITHUB_TOKEN ? ['/pro'] : [] crawlLinks: true
// } // ignore: !process.env.NUXT_GITHUB_TOKEN ? ['/pro'] : []
// }, }
},
routeRules: { routeRules: {
'/': { redirect: '/getting-started', prerender: false }, '/': { redirect: '/getting-started', prerender: false },