Files
forge/tools/generate-images.ts
zeekayandHanzo Dev 0b4f67a1c2 fix(svg): make svg no longer reverts the webhook icon to the upstream teacup
make svg does rm -rf public/assets/img/svg then regenerates, and the generator
special-cased public/assets/img/gitea.svg into an icon named gitea-gitea — so
every regen deleted the hand-committed hanzo-gitea.svg and wrote the upstream
name back, leaving templates/shared/webhook/icon.tmpl pointing at nothing and
make svg-check red.

That asset turned out to be our own logo rendered at 32px — byte-identical to
public/assets/img/logo.svg but for a trailing newline. So the fix is deletion:
drop the duplicate and the build flag that emitted it, and derive the icon from
logo.svg under our own name (hanzo-hanzo). Icons are now generated, not
hand-written; the regen also repaired 20 internal SVG ids the rename had missed.

Also: svg.ts and favicon-status.ts bindings named for the upstream set, and a
shipped reference config documenting emoji defaults that no longer exist and
three PNGs that were deleted.

Co-authored-by: Hanzo Dev <[email protected]>
2026-07-25 11:29:25 -07:00

60 lines
1.8 KiB
JavaScript
Executable File

#!/usr/bin/env node
import {initWasm, Resvg} from '@resvg/resvg-wasm';
import {optimize} from 'svgo';
import {readFile, writeFile} from 'node:fs/promises';
import {argv, exit} from 'node:process';
async function generate(svg: string, path: string, {size, bg}: {size: number, bg?: boolean}) {
const outputFile = new URL(path, import.meta.url);
if (outputFile.href.endsWith('.svg')) {
const {data} = optimize(svg, {
plugins: [
'preset-default',
'removeDimensions',
{
name: 'addAttributesToSVGElement',
params: {
attributes: [{width: String(size)}, {height: String(size)}],
},
},
],
});
await writeFile(outputFile, data);
return;
}
const resvgJS = new Resvg(svg, {
fitTo: {
mode: 'width',
value: size,
},
...(bg && {background: 'white'}),
});
const renderedImage = resvgJS.render();
const pngBytes = renderedImage.asPng();
await writeFile(outputFile, Buffer.from(pngBytes));
}
async function main() {
const logoSvg = await readFile(new URL('../assets/logo.svg', import.meta.url), 'utf8');
const faviconSvg = await readFile(new URL('../assets/favicon.svg', import.meta.url), 'utf8');
await initWasm(await readFile(new URL(import.meta.resolve('@resvg/resvg-wasm/index_bg.wasm'))));
await Promise.all([
generate(logoSvg, '../public/assets/img/logo.svg', {size: 32}),
generate(logoSvg, '../public/assets/img/logo.png', {size: 512}),
generate(faviconSvg, '../public/assets/img/favicon.svg', {size: 32}),
generate(faviconSvg, '../public/assets/img/favicon.png', {size: 180}),
generate(logoSvg, '../public/assets/img/avatar_default.png', {size: 200}),
generate(logoSvg, '../public/assets/img/apple-touch-icon.png', {size: 180, bg: true}),
]);
}
try {
await main();
} catch (err) {
console.error(err);
exit(1);
}