11---
22import { getCollection , render } from " astro:content" ;
33import type { CollectionKey } from " astro:content" ;
4- import { CONTENT } from " @data/config" ;
4+ import { CONTENT , SIDEBAR_NAVIGATION } from " @data/config" ;
55import DocsLayout from " @/layouts/DocsLayout.astro" ;
66import MdxImage from " @/components/docs/markdown/MdxImage.astro" ;
77import MdxLink from " @/components/docs/markdown/MdxLink.astro" ;
8+ import { buildNavigation } from " @/lib/navigation" ;
89
910export async function getStaticPaths() {
10- const paths: { params: { collection: CollectionKey }; props: { collection: CollectionKey } }[] =
11- [];
11+ const paths: {
12+ params: { collection: CollectionKey };
13+ props: {
14+ collection: CollectionKey ;
15+ nav: Awaited <ReturnType <typeof buildNavigation >>;
16+ doc: Awaited <ReturnType <typeof getCollection >>[number ] | undefined ;
17+ };
18+ }[] = [];
19+
1220 for (const sys of CONTENT .systems ) {
21+ const nav = await buildNavigation (SIDEBAR_NAVIGATION , sys .id );
22+ const entries = await getCollection (sys .id as CollectionKey );
23+
24+ // Check if index doc exists, if not use the default redirect target
25+ let indexDoc = entries .find ((entry ) => entry .id === " index" );
26+
27+ if (! indexDoc ) {
28+ // Find the default doc to render instead
29+ const defaultRedirect = sys .defaultDocRedirect ;
30+ if (defaultRedirect ) {
31+ // Extract slug from redirect path (e.g., "/docs/introduction" -> "introduction")
32+ const baseRoute = sys .route ?? ` /${sys .id } ` ;
33+ const defaultSlug = defaultRedirect
34+ .replace (baseRoute + " /" , " " )
35+ .replace (/ ^ \/ + / , " " );
36+ indexDoc = entries .find ((entry ) => entry .id === defaultSlug );
37+ }
38+ }
39+
1340 paths .push ({
1441 params: { collection: sys .id as CollectionKey },
15- props: { collection: sys .id as CollectionKey },
42+ props: {
43+ collection: sys .id as CollectionKey ,
44+ nav ,
45+ doc: indexDoc ,
46+ },
1647 });
1748 }
49+
1850 return paths ;
1951}
2052
2153const collection = Astro .params .collection as CollectionKey ;
22-
23- const entries = await getCollection (collection );
24- const doc = entries .find ((entry ) => entry .id === " index" );
54+ const { nav, doc } = Astro .props as {
55+ collection: CollectionKey ;
56+ nav: Awaited <ReturnType <typeof buildNavigation >>;
57+ doc: Awaited <ReturnType <typeof getCollection >>[number ] | undefined ;
58+ };
2559
2660if (! doc ) {
27- return Astro .redirect (
28- (CONTENT .systems ?? []).find ((system ) => system .id === collection )?.defaultDocRedirect ??
29- " /" ,
30- );
61+ // Fallback to home if no doc found at all
62+ return Astro .redirect (" /" );
3163}
3264
3365const { Content, headings } = await render (doc );
@@ -38,6 +70,6 @@ const components = {
3870};
3971---
4072
41- <DocsLayout frontmatter ={ doc } headings ={ headings } collection ={ collection } >
73+ <DocsLayout frontmatter ={ doc } headings ={ headings } collection ={ collection } nav = { nav } >
4274 <Content components ={ components } />
4375</DocsLayout >
0 commit comments