refactor guide pages to use content collections

also configuration->guide
This commit is contained in:
outfoxxed 2025-05-13 20:56:31 -07:00
parent a449f976c7
commit b066a48976
Signed by: outfoxxed
GPG key ID: 4C88A185FB89301E
13 changed files with 68 additions and 83 deletions

View file

@ -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 = {
};
---
<nav class="navtree">
<Tree {...configuration}/>
<Tree {...guide}/>
<Tree {...types}/>
<Link
title="QtQuick Types"

View file

@ -3,7 +3,7 @@ import NavCollapsible from "./NavCollapsible.astro";
import Self from "./Tree.astro";
import Link from "./Link.astro";
interface TreeEntry {
export interface TreeEntry {
title: string;
link: string;
current?: boolean;

View file

@ -5,7 +5,6 @@ export interface Item {
}
export interface GroupedRoutes {
tutorials: { [key: string]: Item[] };
types: { [key: string]: Item[] };
}

View file

@ -38,29 +38,7 @@ export function buildHierarchy(headings: ConfigHeading[]) {
export function groupRoutes(routes: RouteData[]): GroupedRoutes {
const froutes = routes.filter(route => route.name !== "index");
const defaultValue = {
tutorials: {
configuration: [
{ name: "Getting Started", type: "getting-started" },
{ name: "Intro", type: "intro" },
{ name: "Positioning", type: "positioning" },
{ name: "QML Overview", type: "qml-overview" },
],
},
types: {},
};
return froutes.reduce<GroupedRoutes>((acc, route) => {
if (!acc.tutorials) {
acc.tutorials = {
configuration: [
{ name: "Getting Started", type: "getting-started" },
{ name: "Intro", type: "intro" },
{ name: "Positioning", type: "positioning" },
{ name: "QML Overview", type: "qml-overview" },
],
};
}
if (!acc.types) acc.types = {};
if (!acc.types[route.type]) {
@ -72,7 +50,7 @@ export function groupRoutes(routes: RouteData[]): GroupedRoutes {
type: route.type,
});
return acc;
}, defaultValue);
}, { types: {} });
}
export function getQMLTypeLinkObject(unparsed: string) {

11
src/content.config.ts Normal file
View file

@ -0,0 +1,11 @@
import { defineCollection, z } from "astro:content";
import { glob } from "astro/loaders";
const guide = defineCollection({
loader: glob({ pattern: "**/*", base: "src/guide" }),
schema: z.object({
title: z.string(),
}),
});
export const collections = { guide };

View file

@ -1,5 +1,4 @@
---
layout: "@layouts/ConfigLayout.astro"
title: "Getting Started"
---
# {frontmatter.title}

View file

@ -1,5 +1,4 @@
---
layout: "@layouts/ConfigLayout.astro"
title: "Configuration"
description: "Configuring the shell"
---

View file

@ -1,5 +1,4 @@
---
layout: "@layouts/ConfigLayout.astro"
title: "Introduction"
---

View file

@ -1,5 +1,4 @@
---
layout: "@layouts/ConfigLayout.astro"
title: "Positioning"
---
import MD_Title from "@components/MD_Title.tsx"

View file

@ -1,5 +1,4 @@
---
layout: "@layouts/ConfigLayout.astro"
title: "QML Overview"
---
import MD_Title from "@components/MD_Title.tsx"

View file

@ -1,39 +0,0 @@
---
import DocsLayout from "@layouts/DocsLayout.astro";
import TOCIntersectionObserver from "@src/components/hooks/TOCIntersectionObserver.astro";
import TOC from "@components/navigation/sidebars/TOC.astro";
export interface Headings {
slug: string;
text: string;
depth: number;
}
export interface Props {
content: {
title: string;
};
headings: Headings[];
frontmatter?: {
title: string;
description: string;
};
}
const { headings, frontmatter } = Astro.props;
---
<DocsLayout
title={frontmatter!.title}
description={frontmatter!.description}
headings={headings}
>
<div class="docs">
<div class="docs-content">
<hr />
<slot />
</div>
<TOC mobile={false} headings={headings} data-pagefind-ignore/>
</div>
</DocsLayout>
<TOCIntersectionObserver/>

View file

@ -0,0 +1,30 @@
---
import DocsLayout from "@layouts/DocsLayout.astro";
import TOC from "@components/navigation/sidebars/TOC.astro";
import TOCIntersectionObserver from "@src/components/hooks/TOCIntersectionObserver.astro";
import { getCollection, render } from "astro:content";
export async function getStaticPaths() {
const guidePages = await getCollection("guide");
return guidePages.map(page => ({
params: { id: page.id == "index" ? "/" : page.id },
props: { page },
}));
}
const { page } = Astro.props;
const { Content, headings } = await render(page);
---
<DocsLayout title={page.data.title} description="" headings={headings}>
<div class="docs">
<div class="docs-content">
<hr>
<Content/>
</div>
<TOC mobile={false} headings={headings} data-pagefind-ignore/>
</div>
</DocsLayout>
<TOCIntersectionObserver/>

View file

@ -4,7 +4,7 @@ import DocsLayout from "@layouts/DocsLayout.astro";
<DocsLayout title="Quickshell Docs" description="Quickshell Documentation">
<h2>Docs</h2>
<div class="root-nav">
<h3><a href="/docs/configuration">Configuration</a></h3>
<h3><a href="/docs/guide">Guide</a></h3>
<h3><a href="/docs/types">Type Definitions</a></h3>
</div>
</DocsLayout>