refactor guide pages to use content collections
also configuration->guide
This commit is contained in:
parent
a449f976c7
commit
b066a48976
13 changed files with 68 additions and 83 deletions
|
@ -9,24 +9,35 @@ const { currentRoute, currentModule, currentClass } = Astro.props;
|
||||||
|
|
||||||
import { getTypeData } from "@config/io/generateTypeData";
|
import { getTypeData } from "@config/io/generateTypeData";
|
||||||
import { groupRoutes } from "@config/io/helpers";
|
import { groupRoutes } from "@config/io/helpers";
|
||||||
|
import type { TreeEntry } from "./Tree.astro";
|
||||||
import Tree from "./Tree.astro";
|
import Tree from "./Tree.astro";
|
||||||
import Link from "./Link.astro";
|
import Link from "./Link.astro";
|
||||||
|
|
||||||
const routes = await getTypeData();
|
const routes = await getTypeData();
|
||||||
const groupedRoutes = groupRoutes(routes);
|
const groupedRoutes = groupRoutes(routes);
|
||||||
|
|
||||||
const configuration = {
|
import { getCollection } from "astro:content";
|
||||||
title: "Configuration",
|
const guidePages = await getCollection("guide");
|
||||||
link: "/docs/configuration",
|
|
||||||
current: currentRoute.startsWith("configuration"),
|
function genGuideNav(base: string): TreeEntry[] | undefined {
|
||||||
entries: groupedRoutes.tutorials.configuration.map(
|
const pages = guidePages
|
||||||
({ name, type }) => ({
|
.filter(page => page.id.match(`^${base}[^/]*$`) !== null)
|
||||||
title: name,
|
.map(page => ({
|
||||||
link: `/docs/configuration/${type}`,
|
title: page.data.title,
|
||||||
current: currentModule === type,
|
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 = {
|
const types = {
|
||||||
title: "Quickshell Types",
|
title: "Quickshell Types",
|
||||||
|
@ -47,7 +58,7 @@ const types = {
|
||||||
};
|
};
|
||||||
---
|
---
|
||||||
<nav class="navtree">
|
<nav class="navtree">
|
||||||
<Tree {...configuration}/>
|
<Tree {...guide}/>
|
||||||
<Tree {...types}/>
|
<Tree {...types}/>
|
||||||
<Link
|
<Link
|
||||||
title="QtQuick Types"
|
title="QtQuick Types"
|
||||||
|
|
|
@ -3,7 +3,7 @@ import NavCollapsible from "./NavCollapsible.astro";
|
||||||
import Self from "./Tree.astro";
|
import Self from "./Tree.astro";
|
||||||
import Link from "./Link.astro";
|
import Link from "./Link.astro";
|
||||||
|
|
||||||
interface TreeEntry {
|
export interface TreeEntry {
|
||||||
title: string;
|
title: string;
|
||||||
link: string;
|
link: string;
|
||||||
current?: boolean;
|
current?: boolean;
|
||||||
|
|
|
@ -5,7 +5,6 @@ export interface Item {
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface GroupedRoutes {
|
export interface GroupedRoutes {
|
||||||
tutorials: { [key: string]: Item[] };
|
|
||||||
types: { [key: string]: Item[] };
|
types: { [key: string]: Item[] };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -38,29 +38,7 @@ export function buildHierarchy(headings: ConfigHeading[]) {
|
||||||
|
|
||||||
export function groupRoutes(routes: RouteData[]): GroupedRoutes {
|
export function groupRoutes(routes: RouteData[]): GroupedRoutes {
|
||||||
const froutes = routes.filter(route => route.name !== "index");
|
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) => {
|
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) acc.types = {};
|
||||||
|
|
||||||
if (!acc.types[route.type]) {
|
if (!acc.types[route.type]) {
|
||||||
|
@ -72,7 +50,7 @@ export function groupRoutes(routes: RouteData[]): GroupedRoutes {
|
||||||
type: route.type,
|
type: route.type,
|
||||||
});
|
});
|
||||||
return acc;
|
return acc;
|
||||||
}, defaultValue);
|
}, { types: {} });
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getQMLTypeLinkObject(unparsed: string) {
|
export function getQMLTypeLinkObject(unparsed: string) {
|
||||||
|
|
11
src/content.config.ts
Normal file
11
src/content.config.ts
Normal 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 };
|
|
@ -1,5 +1,4 @@
|
||||||
---
|
---
|
||||||
layout: "@layouts/ConfigLayout.astro"
|
|
||||||
title: "Getting Started"
|
title: "Getting Started"
|
||||||
---
|
---
|
||||||
# {frontmatter.title}
|
# {frontmatter.title}
|
|
@ -1,5 +1,4 @@
|
||||||
---
|
---
|
||||||
layout: "@layouts/ConfigLayout.astro"
|
|
||||||
title: "Configuration"
|
title: "Configuration"
|
||||||
description: "Configuring the shell"
|
description: "Configuring the shell"
|
||||||
---
|
---
|
|
@ -1,5 +1,4 @@
|
||||||
---
|
---
|
||||||
layout: "@layouts/ConfigLayout.astro"
|
|
||||||
title: "Introduction"
|
title: "Introduction"
|
||||||
---
|
---
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
---
|
---
|
||||||
layout: "@layouts/ConfigLayout.astro"
|
|
||||||
title: "Positioning"
|
title: "Positioning"
|
||||||
---
|
---
|
||||||
import MD_Title from "@components/MD_Title.tsx"
|
import MD_Title from "@components/MD_Title.tsx"
|
|
@ -1,5 +1,4 @@
|
||||||
---
|
---
|
||||||
layout: "@layouts/ConfigLayout.astro"
|
|
||||||
title: "QML Overview"
|
title: "QML Overview"
|
||||||
---
|
---
|
||||||
import MD_Title from "@components/MD_Title.tsx"
|
import MD_Title from "@components/MD_Title.tsx"
|
|
@ -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/>
|
|
30
src/pages/docs/guide/[...id].astro
Normal file
30
src/pages/docs/guide/[...id].astro
Normal 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/>
|
|
@ -4,7 +4,7 @@ import DocsLayout from "@layouts/DocsLayout.astro";
|
||||||
<DocsLayout title="Quickshell Docs" description="Quickshell Documentation">
|
<DocsLayout title="Quickshell Docs" description="Quickshell Documentation">
|
||||||
<h2>Docs</h2>
|
<h2>Docs</h2>
|
||||||
<div class="root-nav">
|
<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>
|
<h3><a href="/docs/types">Type Definitions</a></h3>
|
||||||
</div>
|
</div>
|
||||||
</DocsLayout>
|
</DocsLayout>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue