From aa6870df20bdde55690baba4371d92ebc28f49be Mon Sep 17 00:00:00 2001 From: Jared Krinke Date: Wed, 8 Dec 2021 21:11:32 -0800 Subject: [PATCH] Link non-post pages in root by default --- main.ts | 19 +++++++++++++------ schema/site.schema.json | 4 ++-- schema/site.ts | 4 ++-- templates.ts | 4 ++-- 4 files changed, 19 insertions(+), 12 deletions(-) diff --git a/main.ts b/main.ts index 84fb2fb..0cb24f7 100644 --- a/main.ts +++ b/main.ts @@ -79,6 +79,13 @@ function replaceLink(link: string) { return link.replace(/^([^/][^:]*)\.md(#[^#]+)?$/, "$1.html$2") } +function capitalize(str: string): string { + if (str.length > 0) { + return str[0].toLocaleUpperCase() + str.substring(1); + } + return str; +} + const noop: GoldsmithPlugin = (_files, _goldsmith) => {}; await Goldsmith() @@ -201,15 +208,15 @@ await Goldsmith() const text = site.header?.text ?? site.description; let links = site.header?.links; if (!links) { - links = site.header?.links ?? { - "home": "index.html", - "archive": "posts/index.html", - }; - + links = {}; for (const file of metadata.collections!.nonPosts) { const pathFromRoot = file.pathFromRoot!; if (pathFromRoot !== "index.html") { - const name = pathFromRoot.replace(/\.[^.]*$/, ""); + const name = capitalize( + pathFromRoot + .replace(/\.[^.]*$/, "") + .replace("-", " ") + ); links[name] = pathFromRoot; } } diff --git a/schema/site.schema.json b/schema/site.schema.json index a5d5044..2eb43c7 100644 --- a/schema/site.schema.json +++ b/schema/site.schema.json @@ -49,7 +49,7 @@ } }, "header": { - "description": "Optional subtitle and top-level links (added to all pages). By default, the site description is used as the subtitle and links to the home page, archive, and non-post pages in the site root are shown.", + "description": "Optional subtitle and top-level links (added to all pages). By default, the site description is used as the subtitle and links to non-post pages in the site root are shown.", "type": "object", "properties": { "text": { @@ -57,7 +57,7 @@ "type": "string" }, "links": { - "description": "Optional map of top-level link names to relative paths or URLs. Use `index.html` to link to the home page and `posts/index.html` to link to the archive. By default, links to the home page, archive, and all non-post pages in the site root are shown.", + "description": "Optional map of top-level link names to relative paths or URLs. Use `index.html` to link to the home page and `posts/index.html` to link to the archive. By default, links to non-post pages in the site root are shown.", "type": "object", "additionalProperties": { "type": "string" diff --git a/schema/site.ts b/schema/site.ts index 953dfd1..2c5254b 100644 --- a/schema/site.ts +++ b/schema/site.ts @@ -23,11 +23,11 @@ export interface SiteMetadata { /** Color used only for syntax highlighting (generally for comments). */ comment?: HexColor; }; - /** Optional subtitle and top-level links (added to all pages). By default, the site description is used as the subtitle and links to the home page, archive, and non-post pages in the site root are shown. */ + /** Optional subtitle and top-level links (added to all pages). By default, the site description is used as the subtitle and links to non-post pages in the site root are shown. */ header?: { /** Optional subtitle (added to all pages). By default, the site description is used as the subtitle. */ text?: string; - /** Optional map of top-level link names to relative paths or URLs. Use `index.html` to link to the home page and `posts/index.html` to link to the archive. By default, links to the home page, archive, and all non-post pages in the site root are shown. */ + /** Optional map of top-level link names to relative paths or URLs. Use `index.html` to link to the home page and `posts/index.html` to link to the archive. By default, links to non-post pages in the site root are shown. */ links?: { [key: string]: string; }; diff --git a/templates.ts b/templates.ts index 5a8a15d..a110e14 100644 --- a/templates.ts +++ b/templates.ts @@ -254,7 +254,7 @@ ${{verbatim: o?.headVerbatim ?? ""}}

${m.site!.title!}

${{verbatim: m.site?.header?.text ? html`

${m.site.header.text}

` : ""}} -${{verbatim: m.site?.header?.links ? html`