diff --git a/.gitignore b/.gitignore index 52edfd4d..a00c05aa 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,5 @@ pnpm-debug.log* .env.production # macOS .DS_Store +# dark cover variants, written by scripts/cover-dark.mjs on every build and dev start +content/blog/**/*.dark.svg diff --git a/package.json b/package.json index 404a33c6..cc2cc472 100644 --- a/package.json +++ b/package.json @@ -15,8 +15,10 @@ "positioning:check": "node scripts/check-positioning.mjs", "seo:smoke": "node scripts/seo-smoke.mjs", "svg:lint": "node scripts/svg-text-fit.mjs", + "cover:spec": "node scripts/cover-spec.mjs", + "cover:dark": "node scripts/cover-dark.mjs", "og:images": "node scripts/og-images.mjs", - "build": "node scripts/check-positioning.mjs && node scripts/gen-zh-hant.mjs && node scripts/content-lint.mjs --published && node scripts/svg-text-fit.mjs && astro build && node scripts/og-images.mjs && node scripts/content-lint.mjs --dist", + "build": "node scripts/check-positioning.mjs && node scripts/gen-zh-hant.mjs && node scripts/content-lint.mjs --published && node scripts/svg-text-fit.mjs && node scripts/cover-spec.mjs && node scripts/cover-dark.mjs && astro build && node scripts/og-images.mjs && node scripts/content-lint.mjs --dist", "preview": "astro preview", "check": "astro check" }, diff --git a/scripts/cover-dark.mjs b/scripts/cover-dark.mjs new file mode 100644 index 00000000..85ef5fd7 --- /dev/null +++ b/scripts/cover-dark.mjs @@ -0,0 +1,193 @@ +#!/usr/bin/env node +// Dark cover variants: beside every light `cover*.svg` under content/blog, +// write `cover*.dark.svg`, the same drawing with each colour swapped for its +// dark counterpart (scripts/lib/cover-colors.mjs: the site's token pairs, +// then OKLCH lightness mirroring for every other colour). +// +// node scripts/cover-dark.mjs [--verbose] (pnpm cover:dark; runs in `pnpm build` and `pnpm dev`) +// +// The variants are build output, not source: .gitignore keeps them out of the +// repo and this script rewrites them from the light covers on every build, so +// a cover edit cannot leave a stale dark copy behind. The templates +// (src/lib/cover-variant.ts) render both images, lazy, and show one by the +// page's `data-theme`; the hidden one is never fetched. +// +// What is rewritten: `fill`, `stroke`, `stop-color` and `color`, as +// attributes, in `style` attributes and in `