From 9bfd6b12fe0359e6a6591cb987f95d6a36bd656d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philippe=20Rivi=C3=A8re?= Date: Wed, 21 Aug 2024 14:12:59 +0200 Subject: [PATCH] boolean private option to skip the default font links --- docs/config.md | 4 ---- observablehq.config.ts | 7 +++---- src/config.ts | 29 +++++++++++++++++------------ 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/docs/config.md b/docs/config.md index 47797f058..fa4d8624b 100644 --- a/docs/config.md +++ b/docs/config.md @@ -300,7 +300,3 @@ The set of replacements for straight double and single quotes used when the [**t ## linkify If true (the default), automatically convert URL-like text to links in Markdown. - -## extraHead - -An HTML fragment to add at the beginning of the [head](#head). Defaults to the links necessary to use the Source Serif Pro font from Google Fonts (see [#423](https://github.com/observablehq/framework/issues/423)). diff --git a/observablehq.config.ts b/observablehq.config.ts index 1fd987a7a..53efc56f4 100644 --- a/observablehq.config.ts +++ b/observablehq.config.ts @@ -15,9 +15,6 @@ export default { root: "docs", output: "docs/.observablehq/dist", title: "Observable Framework", - extraHead: ` - -`, pages: [ {name: "What is Framework?", path: "/what-is-framework"}, {name: "Getting started", path: "/getting-started"}, @@ -89,7 +86,8 @@ export default { {name: "Contributing", path: "/contributing", pager: false} ], base: "/framework", - head: ` + head: ` + ${ @@ -100,6 +98,7 @@ export default { : "" } `, + _ignoreDefaultFontLinks: true, header: `
diff --git a/src/config.ts b/src/config.ts index ed35de1bc..3bbb65fd6 100644 --- a/src/config.ts +++ b/src/config.ts @@ -105,7 +105,6 @@ export interface ConfigSpec { head?: unknown; header?: unknown; footer?: unknown; - extraHead?: unknown; interpreters?: unknown; title?: unknown; pages?: unknown; @@ -116,6 +115,7 @@ export interface ConfigSpec { quotes?: unknown; cleanUrls?: unknown; markdownIt?: unknown; + _ignoreDefaultFontLinks?: unknown; } interface ScriptSpec { @@ -238,7 +238,7 @@ export function normalizeConfig(spec: ConfigSpec = {}, defaultRoot?: string, wat const sidebar = spec.sidebar === undefined ? undefined : Boolean(spec.sidebar); const scripts = spec.scripts === undefined ? [] : normalizeScripts(spec.scripts); const head = combine( - pageFragment(spec.extraHead === undefined ? defaultExtraHead() : spec.extraHead), + spec._ignoreDefaultFontLinks ? null : defaultFontHeaders(), pageFragment(spec.head === undefined ? "" : spec.head) ); const header = pageFragment(spec.header === undefined ? "" : spec.header); @@ -293,7 +293,7 @@ function defaultFooter(): string { )}">${formatLocaleDate(date)}.`; } -function defaultExtraHead(): string { +function defaultFontHeaders(): string { const href = "https://fonts.googleapis.com/css2?family=Source+Serif+Pro:ital,wght@0,400;0,600;0,700;1,400;1,600;1,700&display=swap"; return ` @@ -430,13 +430,18 @@ export function stringOrNull(spec: unknown): string | null { return spec == null || spec === false ? null : String(spec); } -function combine(...parts: (PageFragmentFunction | string | null)[]): PageFragmentFunction | string | null { - parts = parts.filter((d) => d); - return parts.length > 1 - ? function ({title, data, path}) { - return Array.from(parts, (f) => (typeof f === "function" ? f({title, data, path}) : f)) - .filter((d) => d != null) - .join("\n"); - } - : parts[0] ?? null; +function combine( + links: string | null, + head: PageFragmentFunction | string | null +): PageFragmentFunction | string | null { + return links + ? typeof head === "function" + ? (d) => { + const h = head(d); + return h ? `${links}\n${h}` : links; + } + : head + ? `${links}\n${head}` + : links + : head; }