From b066a4897697f778bb009ae0fd08c5248dc462a7 Mon Sep 17 00:00:00 2001 From: outfoxxed Date: Tue, 13 May 2025 20:56:31 -0700 Subject: [PATCH] refactor guide pages to use content collections also configuration->guide --- .../navigation/sidebars/nav/RootNav.astro | 37 +++++++++++------- .../navigation/sidebars/nav/Tree.astro | 2 +- src/components/navigation/sidebars/types.d.ts | 1 - src/config/io/helpers.ts | 24 +----------- src/content.config.ts | 11 ++++++ .../getting-started.mdx | 1 - .../docs/configuration => guide}/index.mdx | 1 - .../docs/configuration => guide}/intro.mdx | 1 - .../configuration => guide}/positioning.mdx | 1 - .../configuration => guide}/qml-overview.mdx | 1 - src/layouts/ConfigLayout.astro | 39 ------------------- src/pages/docs/guide/[...id].astro | 30 ++++++++++++++ src/pages/docs/index.astro | 2 +- 13 files changed, 68 insertions(+), 83 deletions(-) create mode 100644 src/content.config.ts rename src/{pages/docs/configuration => guide}/getting-started.mdx (99%) rename src/{pages/docs/configuration => guide}/index.mdx (95%) rename src/{pages/docs/configuration => guide}/intro.mdx (99%) rename src/{pages/docs/configuration => guide}/positioning.mdx (99%) rename src/{pages/docs/configuration => guide}/qml-overview.mdx (99%) delete mode 100644 src/layouts/ConfigLayout.astro create mode 100644 src/pages/docs/guide/[...id].astro diff --git a/src/components/navigation/sidebars/nav/RootNav.astro b/src/components/navigation/sidebars/nav/RootNav.astro index f0d03a4..03bdc85 100644 --- a/src/components/navigation/sidebars/nav/RootNav.astro +++ b/src/components/navigation/sidebars/nav/RootNav.astro @@ -9,24 +9,35 @@ 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); -const configuration = { - title: "Configuration", - link: "/docs/configuration", - current: currentRoute.startsWith("configuration"), - entries: groupedRoutes.tutorials.configuration.map( - ({ name, type }) => ({ - title: name, - link: `/docs/configuration/${type}`, - current: currentModule === type, - }) - ), -}; +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) + .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: "Guide", + link: "/docs/guide", + current: currentRoute.startsWith("guide"), + entries: genGuideNav(""), +} const types = { title: "Quickshell Types", @@ -47,7 +58,7 @@ const types = { }; ---