diff --git a/docs/toc.json b/docs/toc.ts similarity index 80% rename from docs/toc.json rename to docs/toc.ts index 05f5b59d..1e32d42d 100644 --- a/docs/toc.json +++ b/docs/toc.ts @@ -1,6 +1,13 @@ -{ +type RawTableOfContents = Record; + +interface RawTableOfContentsEntry { + title: string; + pages?: [string, string][]; +} + +const toc: RawTableOfContents = { "introduction": { - "title": "Introduction" + "title": "Introduction", }, "getting-started": { "title": "Getting Started", @@ -13,8 +20,8 @@ ["fetching-data", "Fetching data"], ["form-submissions", "Form submissions"], ["adding-interactivity", "Adding interactivity"], - ["deploy-to-production", "Deploy to production"] - ] + ["deploy-to-production", "Deploy to production"], + ], }, "concepts": { "title": "Concepts", @@ -32,11 +39,11 @@ ["plugins", "Plugins"], ["updating", "Updating Fresh"], ["app-wrapper", "Application wrapper"], - ["server-configuration", "Server configuration"] - ] + ["server-configuration", "Server configuration"], + ], }, "integrations": { - "title": "Integrations" + "title": "Integrations", }, "examples": { "title": "Examples", @@ -52,7 +59,9 @@ ["creating-a-crud-api", "Creating a CRUD API"], ["handling-complex-routes", "Handling complex routes"], ["rendering-markdown", "Rendering markdown"], - ["sharing-state-between-islands", "Sharing state between islands"] - ] - } -} + ["sharing-state-between-islands", "Sharing state between islands"], + ], + }, +}; + +export default toc; diff --git a/www/data/docs.ts b/www/data/docs.ts index 86849585..e2a149c2 100644 --- a/www/data/docs.ts +++ b/www/data/docs.ts @@ -1,11 +1,4 @@ -import RAW_TOC from "../../docs/toc.json" assert { type: "json" }; - -type RawTableOfContents = Record; - -interface RawTableOfContentsEntry { - title: string; - pages?: [string, string][]; -} +import toc from "../../docs/toc.ts"; export interface TableOfContentsEntry { slug: string; @@ -29,8 +22,8 @@ export interface TableOfContentsCategoryEntry { export const TABLE_OF_CONTENTS: Record = {}; export const CATEGORIES: TableOfContentsCategory[] = []; -for (const parent in (RAW_TOC as unknown as RawTableOfContents)) { - const rawEntry = (RAW_TOC as unknown as RawTableOfContents)[parent]; +for (const parent in toc) { + const rawEntry = toc[parent]; const href = `/docs/${parent}`; const file = `docs/${parent}/index.md`; const entry = { @@ -46,8 +39,11 @@ for (const parent in (RAW_TOC as unknown as RawTableOfContents)) { entries: [], }; CATEGORIES.push(category); - if (rawEntry.pages) { - for (const [id, title] of rawEntry.pages) { + const filteredPages = rawEntry.pages?.filter(([title, page]) => + title != null && page != null + ); + if (filteredPages) { + for (const [id, title] of filteredPages) { const slug = `${parent}/${id}`; const href = `/docs/${slug}`; const file = `docs/${slug}.md`;