Skip to content

Commit a24c431

Browse files
committed
fix(temp): prose components not being loaded
1 parent d66ce52 commit a24c431

File tree

2 files changed

+204
-0
lines changed

2 files changed

+204
-0
lines changed

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

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
<!-- TODO: remove this once https://github.com/nuxtlabs/docus/pull/1174 gets merged -->
2+
<script setup lang="ts">
3+
import { kebabCase } from 'scule'
4+
import type { ContentNavigationItem, Collections, DocsEnCollectionItem } from '@nuxt/content'
5+
import { findPageHeadline } from '@nuxt/content/utils'
6+
7+
const addPrerenderPath = (path: string) => {
8+
const event = useRequestEvent()
9+
if (event) {
10+
event.node.res.setHeader(
11+
'x-nitro-prerender',
12+
[
13+
event.node.res.getHeader('x-nitro-prerender'),
14+
path,
15+
].filter(Boolean).join(','),
16+
)
17+
}
18+
}
19+
20+
definePageMeta({
21+
layout: 'docs',
22+
})
23+
24+
const route = useRoute()
25+
const { locale, isEnabled, t } = useDocusI18n()
26+
const appConfig = useAppConfig()
27+
const navigation = inject<Ref<ContentNavigationItem[]>>('navigation')
28+
29+
const collectionName = computed(() => isEnabled.value ? `docs_${locale.value}` : 'docs')
30+
31+
const [{ data: page }, { data: surround }] = await Promise.all([
32+
useAsyncData(kebabCase(route.path), () => queryCollection(collectionName.value as keyof Collections).path(route.path).first() as Promise<DocsEnCollectionItem>),
33+
useAsyncData(`${kebabCase(route.path)}-surround`, () => {
34+
return queryCollectionItemSurroundings(collectionName.value as keyof Collections, route.path, {
35+
fields: ['description'],
36+
})
37+
}),
38+
])
39+
40+
if (!page.value) {
41+
throw createError({ statusCode: 404, statusMessage: 'Page not found', fatal: true })
42+
}
43+
44+
if (page.value.layout) {
45+
setPageLayout(page.value.layout as never)
46+
}
47+
48+
// Add the page path to the prerender list
49+
addPrerenderPath(`/raw${route.path}.md`)
50+
51+
const title = page.value.seo?.title || page.value.title
52+
const description = page.value.seo?.description || page.value.description
53+
54+
useSeoMeta({
55+
title,
56+
ogTitle: title,
57+
description,
58+
ogDescription: description,
59+
})
60+
61+
const headline = computed(() => findPageHeadline(navigation?.value, page.value?.path))
62+
defineOgImageComponent('Docs', {
63+
headline: headline.value,
64+
})
65+
66+
const editLink = computed(() => {
67+
if (!appConfig.github) {
68+
return
69+
}
70+
71+
return [
72+
appConfig.github.url,
73+
'edit',
74+
appConfig.github.branch,
75+
appConfig.github.rootDir,
76+
'content',
77+
`${page.value?.stem}.${page.value?.extension}`,
78+
].filter(Boolean).join('/')
79+
})
80+
</script>
81+
82+
<template>
83+
<UPage v-if="page">
84+
<UPageHeader
85+
:title="page.title"
86+
:description="page.description"
87+
:headline="headline"
88+
:ui="{
89+
wrapper: 'flex-row items-center flex-wrap justify-between',
90+
}"
91+
>
92+
<template #links>
93+
<UButton
94+
v-for="(link, index) in page.links"
95+
:key="index"
96+
size="sm"
97+
v-bind="link"
98+
/>
99+
100+
<DocsPageHeaderLinks />
101+
</template>
102+
</UPageHeader>
103+
104+
<UPageBody>
105+
<ContentRenderer
106+
v-if="page"
107+
:value="page"
108+
/>
109+
110+
<USeparator>
111+
<div
112+
v-if="editLink"
113+
class="flex items-center gap-2 text-sm text-muted"
114+
>
115+
<UButton
116+
variant="link"
117+
color="neutral"
118+
:to="editLink"
119+
target="_blank"
120+
icon="i-lucide-pen"
121+
:ui="{ leadingIcon: 'size-4' }"
122+
>
123+
{{ t('docs.edit') }}
124+
</UButton>
125+
<span>{{ t('common.or') }}</span>
126+
<UButton
127+
variant="link"
128+
color="neutral"
129+
:to="`${appConfig.github.url}/issues/new/choose`"
130+
target="_blank"
131+
icon="i-lucide-alert-circle"
132+
:ui="{ leadingIcon: 'size-4' }"
133+
>
134+
{{ t('docs.report') }}
135+
</UButton>
136+
</div>
137+
</USeparator>
138+
<UContentSurround :surround="surround" />
139+
</UPageBody>
140+
141+
<template
142+
v-if="page?.body?.toc?.links?.length"
143+
#right
144+
>
145+
<UContentToc
146+
highlight
147+
:title="appConfig.toc?.title || t('docs.toc')"
148+
:links="page.body?.toc?.links"
149+
>
150+
<template #bottom>
151+
<DocsAsideRightBottom />
152+
</template>
153+
</UContentToc>
154+
</template>
155+
</UPage>
156+
</template>

app/pages/[[lang]]/index.vue

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<!-- TODO: remove this once https://github.com/nuxtlabs/docus/pull/1174 gets merged -->
2+
<script setup lang="ts">
3+
import type { Collections } from '@nuxt/content'
4+
5+
const route = useRoute()
6+
const { locale, isEnabled } = useDocusI18n()
7+
8+
// Dynamic collection name based on i18n status
9+
const collectionName = computed(() => isEnabled.value ? `landing_${locale.value}` : 'landing')
10+
11+
const { data: page } = await useAsyncData(collectionName.value, () => queryCollection(collectionName.value as keyof Collections).path(route.path).first())
12+
if (!page.value) {
13+
throw createError({ statusCode: 404, statusMessage: 'Page not found', fatal: true })
14+
}
15+
16+
// Reconsider it once this is implemented: https://github.com/nuxt/content/issues/3419
17+
const prose = page.value.meta?.prose as boolean
18+
const title = page.value.seo?.title || page.value.title
19+
const description = page.value.seo?.description || page.value.description
20+
21+
useSeoMeta({
22+
title,
23+
description,
24+
ogTitle: title,
25+
ogDescription: description,
26+
})
27+
28+
if (page.value?.seo?.ogImage) {
29+
useSeoMeta({
30+
ogImage: page.value.seo.ogImage,
31+
twitterImage: page.value.seo.ogImage,
32+
})
33+
}
34+
else {
35+
defineOgImageComponent('Landing', {
36+
title,
37+
description,
38+
})
39+
}
40+
</script>
41+
42+
<template>
43+
<ContentRenderer
44+
v-if="page"
45+
:value="page"
46+
:prose="prose"
47+
/>
48+
</template>

0 commit comments

Comments
 (0)