spicebook/docs-site/patches/fix-starlight-head.mjs
Ryan Malloy ad7e80c722 Add Starlight docs site with API reference, guides, and embedding docs
Starlight site at docs-site/ following warehack.ing cookie-cutter pattern
(3-compose split, Caddy prod stage, Makefile targets). 15 content pages
covering simulation engines, waveform viewer, schematics, embedding with
postMessage theme sync, and full REST API reference adapted from llms.txt.
Blue accent theme matching SpiceBook's application palette. Adds docs link
to homepage reference section.
2026-03-06 11:55:21 -07:00

36 lines
1.1 KiB
JavaScript

/**
* Patches @astrojs/starlight to handle undefined `data.head` in frontmatter.
*
* Starlight 0.37.x assumes docsSchema() defaults `head` to [] via Zod, but
* the content loader doesn't always apply this default, causing:
* "Cannot read properties of undefined (reading 'some')"
*
* This adds a nullish coalescing fallback: `data.head ?? []`
*/
import { readFileSync, writeFileSync } from 'node:fs';
const file = 'node_modules/@astrojs/starlight/utils/head.ts';
try {
let src = readFileSync(file, 'utf8');
const target = 'config.head, data.head)';
const replacement = 'config.head, data.head ?? [])';
if (src.includes(replacement)) {
console.log('[patch] head.ts already patched, skipping.');
process.exit(0);
}
if (!src.includes(target)) {
console.warn('[patch] Could not find target string in head.ts — Starlight may have been updated.');
process.exit(0);
}
src = src.replace(target, replacement);
writeFileSync(file, src, 'utf8');
console.log('[patch] Patched head.ts: data.head ?? []');
} catch (err) {
console.warn('[patch] Could not patch head.ts:', err.message);
}