www: convert toc to .ts (#1381)

This commit is contained in:
Reed von Redwitz
2023-07-04 10:49:00 +02:00
committed by GitHub
parent 45ba10e9ee
commit efcaec3658
2 changed files with 28 additions and 23 deletions
+20 -11
View File
@@ -1,6 +1,13 @@
{ type RawTableOfContents = Record<string, RawTableOfContentsEntry>;
interface RawTableOfContentsEntry {
title: string;
pages?: [string, string][];
}
const toc: RawTableOfContents = {
"introduction": { "introduction": {
"title": "Introduction" "title": "Introduction",
}, },
"getting-started": { "getting-started": {
"title": "Getting Started", "title": "Getting Started",
@@ -13,8 +20,8 @@
["fetching-data", "Fetching data"], ["fetching-data", "Fetching data"],
["form-submissions", "Form submissions"], ["form-submissions", "Form submissions"],
["adding-interactivity", "Adding interactivity"], ["adding-interactivity", "Adding interactivity"],
["deploy-to-production", "Deploy to production"] ["deploy-to-production", "Deploy to production"],
] ],
}, },
"concepts": { "concepts": {
"title": "Concepts", "title": "Concepts",
@@ -32,11 +39,11 @@
["plugins", "Plugins"], ["plugins", "Plugins"],
["updating", "Updating Fresh"], ["updating", "Updating Fresh"],
["app-wrapper", "Application wrapper"], ["app-wrapper", "Application wrapper"],
["server-configuration", "Server configuration"] ["server-configuration", "Server configuration"],
] ],
}, },
"integrations": { "integrations": {
"title": "Integrations" "title": "Integrations",
}, },
"examples": { "examples": {
"title": "Examples", "title": "Examples",
@@ -52,7 +59,9 @@
["creating-a-crud-api", "Creating a CRUD API"], ["creating-a-crud-api", "Creating a CRUD API"],
["handling-complex-routes", "Handling complex routes"], ["handling-complex-routes", "Handling complex routes"],
["rendering-markdown", "Rendering markdown"], ["rendering-markdown", "Rendering markdown"],
["sharing-state-between-islands", "Sharing state between islands"] ["sharing-state-between-islands", "Sharing state between islands"],
] ],
} },
} };
export default toc;
+8 -12
View File
@@ -1,11 +1,4 @@
import RAW_TOC from "../../docs/toc.json" assert { type: "json" }; import toc from "../../docs/toc.ts";
type RawTableOfContents = Record<string, RawTableOfContentsEntry>;
interface RawTableOfContentsEntry {
title: string;
pages?: [string, string][];
}
export interface TableOfContentsEntry { export interface TableOfContentsEntry {
slug: string; slug: string;
@@ -29,8 +22,8 @@ export interface TableOfContentsCategoryEntry {
export const TABLE_OF_CONTENTS: Record<string, TableOfContentsEntry> = {}; export const TABLE_OF_CONTENTS: Record<string, TableOfContentsEntry> = {};
export const CATEGORIES: TableOfContentsCategory[] = []; export const CATEGORIES: TableOfContentsCategory[] = [];
for (const parent in (RAW_TOC as unknown as RawTableOfContents)) { for (const parent in toc) {
const rawEntry = (RAW_TOC as unknown as RawTableOfContents)[parent]; const rawEntry = toc[parent];
const href = `/docs/${parent}`; const href = `/docs/${parent}`;
const file = `docs/${parent}/index.md`; const file = `docs/${parent}/index.md`;
const entry = { const entry = {
@@ -46,8 +39,11 @@ for (const parent in (RAW_TOC as unknown as RawTableOfContents)) {
entries: [], entries: [],
}; };
CATEGORIES.push(category); CATEGORIES.push(category);
if (rawEntry.pages) { const filteredPages = rawEntry.pages?.filter(([title, page]) =>
for (const [id, title] of rawEntry.pages) { title != null && page != null
);
if (filteredPages) {
for (const [id, title] of filteredPages) {
const slug = `${parent}/${id}`; const slug = `${parent}/${id}`;
const href = `/docs/${slug}`; const href = `/docs/${slug}`;
const file = `docs/${slug}.md`; const file = `docs/${slug}.md`;