11<script setup lang="ts">
2- import type { NavItem , ParsedContent } from ' @nuxt/content'
2+ import type { ContentNavigationItem } from ' @nuxt/content'
33
44const runtime = useRuntimeConfig ()
5- const {
6- navigation,
7- page,
8- next,
9- prev,
10- } = useContent () as {
11- navigation: Ref <NavItem []>
12- page: Ref <ParsedContent >
13- next: Ref <ParsedContent | undefined >
14- prev: Ref <ParsedContent | undefined >
15- }
5+ const route = useRoute ()
6+ const { data : page } = useAsyncData (route .path , () => {
7+ return queryCollection (' tutorials' ).path (route .path ).first ()
8+ })
9+ const { data : navigation } = useAsyncData (` navigation ` , () => {
10+ return queryCollectionNavigation (' tutorials' )
11+ })
12+ const { data : surroundings } = useAsyncData (` ${route .path }-surroundings ` , () => {
13+ return queryCollectionItemSurroundings (' tutorials' , route .path , {
14+ fields: [' title' , ' description' ],
15+ })
16+ })
17+
18+ const prev = computed (() => surroundings .value ?.[0 ])
19+ const next = computed (() => surroundings .value ?.[1 ])
1620
1721interface BreadcrumbItem {
1822 title: string
1923 path? : string
2024}
2125
22- function findNavItemFromPath(path : string , items = navigation .value ): NavItem | undefined {
23- const item = items .find (i => i ._path === path )
26+ function findNavItemFromPath(
27+ path : string ,
28+ items : ContentNavigationItem [] | null = navigation .value ,
29+ ): ContentNavigationItem | undefined {
30+ const item = items ?.find (i => i .path === path )
2431 if (item )
2532 return item
2633
2734 const parts = path .split (' /' ).filter (Boolean )
2835 for (let i = parts .length - 1 ; i > 0 ; i -- ) {
2936 const parentPath = ` /${parts .slice (0 , i ).join (' /' )} `
30- const parent = items .find (i => i ._path === parentPath )
37+ const parent = items ? .find (i => i .path === parentPath )
3138 if (parent )
3239 return findNavItemFromPath (path , parent .children || [])
3340 }
3441}
3542
36- const contentPath = computed (() => page .value ?._path as string | undefined )
43+ const contentPath = computed (() => page .value ?.path as string | undefined )
3744const breadcrumbs = computed (() => {
3845 const parts = contentPath .value ?.split (' /' ).filter (Boolean ) || []
3946 const breadcrumbs = parts
@@ -58,8 +65,8 @@ const breadcrumbs = computed(() => {
5865const ui = useUiState ()
5966
6067const sourceUrl = computed (() =>
61- page .value ?._file
62- ? ` ${runtime .public .repoUrl }/edit/main/content/${page .value ._file } `
68+ page .value ?.id
69+ ? ` ${runtime .public .repoUrl }/edit/main/content/${page .value .id } `
6370 : undefined ,
6471)
6572
@@ -94,24 +101,24 @@ router.beforeEach(() => {
94101 </div >
95102 <div relative h-full of-hidden >
96103 <article ref =" docsEl" class =" max-w-none prose" h-full of-auto p6 >
97- <ContentDoc />
104+ <ContentRenderer v-if = " page " :key = " page.id " :value = " page " />
98105 <div mt8 py2 grid =" ~ cols-[1fr_1fr] gap-4" >
99106 <div >
100107 <ContentNavCard
101108 v-if =" prev"
102- :to =" prev._path "
109+ :to =" prev.path "
103110 :title =" prev.title"
104- :description =" prev.description"
111+ :description =" prev.description as string "
105112 subheader =" Previous section"
106113 icon =" i-ph-arrow-left"
107114 />
108115 </div >
109116 <div >
110117 <ContentNavCard
111118 v-if =" next"
112- :to =" next._path "
119+ :to =" next.path "
113120 :title =" next.title"
114- :description =" next.description"
121+ :description =" next.description as string "
115122 subheader =" Next section"
116123 icon =" i-ph-arrow-right"
117124 items-end text-right
@@ -140,7 +147,7 @@ router.beforeEach(() => {
140147 absolute left-0 right-0 top-0 max-h-60vh py2
141148 backdrop-blur-10 bg-base important-bg-opacity-80
142149 >
143- <ContentNavItem v-for =" item of navigation" :key =" item.url " :item =" item" />
150+ <ContentNavItem v-for =" item of navigation" :key =" item.path " :item =" item" />
144151 </div >
145152 </Transition >
146153 </div >
0 commit comments