quickshell-web/src/components/navigation/sidebars/nav/RootNav.astro

74 lines
1.9 KiB
Text

---
export interface Props {
currentRoute: string;
currentModule: string;
currentClass: string;
}
const { currentRoute, currentModule, currentClass } = Astro.props;
import { getTypeData } from "@config/io/generateTypeData";
import { groupRoutes } from "@config/io/helpers";
import type { TreeEntry } from "./Tree.astro";
import Tree from "./Tree.astro";
import Link from "./Link.astro";
const routes = await getTypeData();
const groupedRoutes = groupRoutes(routes);
import { getCollection } from "astro:content";
const guidePages = await getCollection("guide");
function genGuideNav(base: string): TreeEntry[] | undefined {
const pages = guidePages
.filter(page => page.id.match(`^${base}[^/]*$`) !== null && page.id != "index")
.sort((a, b) => a.data.index - b.data.index)
.map(page => ({
title: page.data.title,
link: `/docs/guide/${page.id}`,
current: currentModule === page.id,
entries: genGuideNav(page.id + "/"),
}));
return pages.length == 0 ? undefined : pages;
}
const guide = {
title: "Usage Guide",
link: "/docs/guide",
current: currentRoute.startsWith("guide"),
entries: genGuideNav(""),
}
const types = {
title: "Quickshell Types",
link: "/docs/types",
current: currentRoute.startsWith("types"),
entries: Object.entries(groupedRoutes.types).map(
([module, items]) => ({
title: module,
link: `/docs/types/${module}`,
current: currentModule === module,
entries: items.map(type => ({
title: type.name,
link: `/docs/types/${module}/${type.name}`,
current: currentClass === type.name,
})),
})
),
};
---
<nav class="navtree">
<Tree {...guide}/>
<Tree {...types}/>
<Link
title="QtQuick Types"
link="https://doc.qt.io/qt-6/qtquick-qmlmodule.html"
showIcon={true}
/>
<Link
title="Quickshell Examples"
link="https://git.outfoxxed.me/outfoxxed/quickshell-examples"
showIcon={true}
/>
</nav>