diff --git a/docs/docusaurus.config.js b/docs/docusaurus.config.js index 882859e..3a1fe06 100644 --- a/docs/docusaurus.config.js +++ b/docs/docusaurus.config.js @@ -14,6 +14,18 @@ const config = { projectName: "Qoderian", trailingSlash: false, + headTags: [ + { + tagName: "link", + attributes: { + rel: "icon", + type: "image/svg+xml", + // headTags hrefs are emitted verbatim, so the baseUrl prefix is manual. + href: "/Qoderian/img/favicon.svg", + }, + }, + ], + onBrokenLinks: "throw", i18n: { diff --git a/docs/scripts/sync-assets.mjs b/docs/scripts/sync-assets.mjs index b556fa8..2e2f912 100644 --- a/docs/scripts/sync-assets.mjs +++ b/docs/scripts/sync-assets.mjs @@ -1,6 +1,6 @@ // Copies shared repository assets into the website's static dir so the // published site can reference them without committing duplicates. -import { copyFileSync, mkdirSync } from "node:fs"; +import { copyFileSync, mkdirSync, readFileSync, writeFileSync } from "node:fs"; import { dirname, join } from "node:path"; import { fileURLToPath } from "node:url"; @@ -19,3 +19,20 @@ for (const [from, to] of targets) { copyFileSync(join(repoRoot, from), dest); console.log(`synced ${from} -> docs/${to}`); } + +// The favicon reuses the plugin icon, but a favicon has no surrounding text +// color for currentColor to inherit, so the theme switch is made explicit: +// black mark on light browser chrome, white on dark. +const favicon = readFileSync(join(repoRoot, "src/assets/qoder-icon.svg"), "utf8") + .replace('fill="currentColor"', 'class="qf"') + .replace('stroke="currentColor"', 'class="qs"') + .replace( + /]*>/, + (tag) => + `${tag}", + ); +const faviconDest = join(siteDir, "static/img/favicon.svg"); +mkdirSync(dirname(faviconDest), { recursive: true }); +writeFileSync(faviconDest, favicon); +console.log("built src/assets/qoder-icon.svg -> docs/static/img/favicon.svg");