Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

_ignoreDefaultFontLinks boolean private config option #1595

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,3 @@ The set of replacements for straight double and single quotes used when the [**t
## linkify <a href="https://github.com/observablehq/framework/releases/tag/v1.7.0" class="observablehq-version-badge" data-version="^1.7.0" title="Added in 1.7.0"></a>

If true (the default), automatically convert URL-like text to links in Markdown.

## extraHead <a href="https://github.com/observablehq/framework/pull/1588" class="observablehq-version-badge" data-version="prerelease" title="Added in #1588"></a>

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)).
7 changes: 3 additions & 4 deletions observablehq.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ export default {
root: "docs",
output: "docs/.observablehq/dist",
title: "Observable Framework",
extraHead: `<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link rel="preload" as="style" href="https://fonts.googleapis.com/css2?family=Inter:ital,opsz,wght@0,14..32,100..900;1,14..32,100..900&family=Spline+Sans+Mono:ital,wght@0,300..700;1,300..700&display=swap" crossorigin>
<link rel="stylesheet" type="text/css" href="https://fonts.googleapis.com/css2?family=Inter:ital,opsz,wght@0,14..32,100..900;1,14..32,100..900&family=Spline+Sans+Mono:ital,wght@0,300..700;1,300..700&display=swap" crossorigin>`,
pages: [
{name: "What is Framework?", path: "/what-is-framework"},
{name: "Getting started", path: "/getting-started"},
Expand Down Expand Up @@ -89,7 +86,8 @@ export default {
{name: "Contributing", path: "/contributing", pager: false}
],
base: "/framework",
head: `<link rel="preload" as="style" href="https://fonts.googleapis.com/css2?family=Inter:ital,opsz,wght@0,14..32,100..900;1,14..32,100..900&family=Spline+Sans+Mono:ital,wght@0,300..700;1,300..700&display=swap" crossorigin>
head: `<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link rel="preload" as="style" href="https://fonts.googleapis.com/css2?family=Inter:ital,opsz,wght@0,14..32,100..900;1,14..32,100..900&family=Spline+Sans+Mono:ital,wght@0,300..700;1,300..700&display=swap" crossorigin>
<link rel="stylesheet" type="text/css" href="https://fonts.googleapis.com/css2?family=Inter:ital,opsz,wght@0,14..32,100..900;1,14..32,100..900&family=Spline+Sans+Mono:ital,wght@0,300..700;1,300..700&display=swap" crossorigin>
<link rel="apple-touch-icon" href="/observable.png">
<link rel="icon" type="image/png" href="/observable.png" sizes="32x32">${
Expand All @@ -100,6 +98,7 @@ export default {
: ""
}
<script type="module">/Win/.test(navigator.platform) || Array.from(document.querySelectorAll(".win"), (e) => e.remove())</script>`,
_ignoreDefaultFontLinks: true,
header: `<div style="display: flex; align-items: center; gap: 0.5rem; height: 2.2rem; margin: -1.5rem -2rem 2rem -2rem; padding: 0.5rem 2rem; border-bottom: solid 1px var(--theme-foreground-faintest); font: 500 16px var(--sans-serif);">
<a href="https://observablehq.com/" target="_self" rel="" style="display: flex; align-items: center;">
<svg width="22" height="22" viewBox="0 0 21.92930030822754 22.68549919128418" fill="currentColor">
Expand Down
29 changes: 17 additions & 12 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ export interface ConfigSpec {
head?: unknown;
header?: unknown;
footer?: unknown;
extraHead?: unknown;
interpreters?: unknown;
title?: unknown;
pages?: unknown;
Expand All @@ -116,6 +115,7 @@ export interface ConfigSpec {
quotes?: unknown;
cleanUrls?: unknown;
markdownIt?: unknown;
_ignoreDefaultFontLinks?: unknown;
}

interface ScriptSpec {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -293,7 +293,7 @@ function defaultFooter(): string {
)}">${formatLocaleDate(date)}</a>.`;
}

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&amp;display=swap";
return `<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
Expand Down Expand Up @@ -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;
}