@@ -5,8 +5,6 @@ export interface Props {
55 currentClass? : string ;
66}
77
8- const { currentRoute, currentModule, currentClass } = Astro .props ;
9-
108import { getModulesData } from " @config/io/generateTypeData" ;
119import type { TreeEntry } from " ./Tree.astro" ;
1210import Tree from " ./Tree.astro" ;
@@ -18,50 +16,64 @@ const modules = await getModulesData();
1816import { getCollection } from " astro:content" ;
1917const guidePages = await getCollection (" guide" );
2018
21- function genGuideNav(base : string ): TreeEntry [] | undefined {
19+ interface NavTree {
20+ title: string ,
21+ slug: string ,
22+ entries? : NavTree [],
23+ }
24+
25+ const currentPath = Astro .url .pathname .slice (1 ).split (' /' );
26+
27+ function mkTree(mount : string , pathIdx : number , { title , slug , entries }: NavTree ): TreeEntry {
28+ const link = ` ${mount }/${slug } ` ;
29+
30+ return {
31+ title ,
32+ link ,
33+ current: currentPath [pathIdx ] === slug ,
34+ entries: entries ?.map (entry => mkTree (link , pathIdx + 1 , entry )),
35+ };
36+ }
37+
38+ function genGuideNav(base : string ): NavTree [] | undefined {
2239 const pages = guidePages
2340 .filter (page => page .id .match (` ^${base }[^/]*$ ` ) !== null && page .id !== " index" )
2441 .sort ((a , b ) => a .data .index - b .data .index )
2542 .map (page => ({
2643 title: page .data .title ,
27- link: ` /docs/guide/${page .id } ` ,
28- current: currentModule === page .id ,
44+ slug: page .id ,
2945 entries: genGuideNav (page .id + " /" ),
3046 }));
3147
3248 return pages .length === 0 ? undefined : pages ;
3349}
3450
35- const guide = {
51+ const guide = mkTree ( " /docs " , 1 , {
3652 title: " Usage Guide" ,
37- link: " /docs/guide" ,
38- current: currentRoute ?.startsWith (" guide" ) ?? false ,
53+ slug: " guide" ,
3954 entries: genGuideNav (" " ),
40- }
55+ });
4156
42- const types = {
57+ const types = mkTree ( " /docs " , 1 , {
4358 title: " Quickshell Types" ,
44- link: " /docs/types" ,
45- current: currentRoute ?.startsWith (" types" ) ?? false ,
59+ slug: " types" ,
4660 entries: modules .map (module => ({
4761 title: module .name ,
48- link: ` /docs/types/${module .name } ` ,
49- current: currentModule === module .name ,
62+ slug: module .name ,
5063 entries: module .types .map (type => ({
5164 title: type .name ,
52- link: ` /docs/types/${module .name }/${type .name } ` ,
53- current: currentClass === type .name ,
65+ slug: type .name ,
5466 }))
5567 }))
56- };
68+ }) ;
5769
5870---
5971<nav class =" navtree" >
6072 <VersionSelector title =" Versions" link =`${Astro .currentLocale }` current />
6173 <Link
6274 title =" About Quickshell"
6375 link =" /about"
64- current ={ currentRoute === " about" }
76+ current ={ Astro . url . pathname === " / about" }
6577 />
6678 <Tree {... guide }/>
6779 <Tree {... types }/>
0 commit comments