wip: inline diagram SVG

This commit is contained in:
2026-01-12 18:32:47 +00:00
parent 4b72967556
commit 5739a3c998
35 changed files with 99 additions and 104 deletions

View File

@@ -9,6 +9,7 @@ import * as fs from "node:fs";
import * as path from "node:path";
import * as semver from "semver";
import { $ } from "bun";
import { optimize as optimizeSvg } from "svgo";
import { config } from "../src/config";
const updateConfig = {
@@ -18,7 +19,6 @@ version: {{version}}
---
{{content}}`,
outputDir: "src/content/spec",
publicDir: "public/spec",
};
/**
@@ -119,22 +119,20 @@ function removeStaleSpecs(versionsToKeep: string[]): void {
const keepSet = new Set(versionsToKeep);
let removedAny = false;
for (const dir of [updateConfig.outputDir, updateConfig.publicDir]) {
if (!fs.existsSync(dir)) continue;
if (!fs.existsSync(updateConfig.outputDir)) return;
const files = fs.readdirSync(dir);
for (const file of files) {
// Extract version from filename (e.g., "1.0.0-rc.1.md" -> "1.0.0-rc.1")
const version = path.basename(file, path.extname(file));
if (!keepSet.has(version)) {
if (!removedAny) {
console.log("\nRemoving stale spec files:");
removedAny = true;
}
const filePath = path.join(dir, file);
fs.unlinkSync(filePath);
console.log(` ${filePath}`);
const files = fs.readdirSync(updateConfig.outputDir);
for (const file of files) {
// Extract version from filename (e.g., "1.0.0-rc.1.md" -> "1.0.0-rc.1")
const version = path.basename(file, path.extname(file));
if (!keepSet.has(version)) {
if (!removedAny) {
console.log("\nRemoving stale spec files:");
removedAny = true;
}
const filePath = path.join(updateConfig.outputDir, file);
fs.unlinkSync(filePath);
console.log(` ${filePath}`);
}
}
@@ -211,10 +209,11 @@ async function main(): Promise<void> {
const mdPath = path.join(updateConfig.outputDir, `${version}.md`);
writeFile(mdPath, spec.body);
// Write SVG diagram to public directory
// Write SVG diagram next to markdown (with metadata stripped)
if (spec.diagram) {
const svgPath = path.join(updateConfig.publicDir, `${version}.svg`);
writeFile(svgPath, spec.diagram);
const svgPath = path.join(updateConfig.outputDir, `${version}.svg`);
const optimizedSvg = optimizeSvg(spec.diagram).data;
writeFile(svgPath, optimizedSvg);
}
} catch (error) {
console.error(`Error processing version ${version}:`, error);