| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- #!/usr/bin/env node
- /**
- * Build icons.svg — one inline SVG sprite combined from the Font Awesome Pro kit's
- * pre-built per-style sprites under node_modules/@awesome.me/kit-<id>/icons/sprites/.
- *
- * Symbol ids are namespaced `dw-<name>` (e.g. dw-house). Consumed via the dw_icon()
- * helper (inc/template.php) or directly: <svg class="dw-icon"><use href="#dw-house"></use></svg>.
- *
- * Run: npm run icons (also chained into `npm run build`).
- * The kit is the curated icon set, so the sprite is exactly the icons we use (~40, ~40 KB)
- * — replacing the 689 KB Font Awesome webfont.
- */
- import { readFileSync, writeFileSync, readdirSync } from 'node:fs';
- import { resolve } from 'node:path';
- const scope = 'node_modules/@awesome.me';
- let kit;
- try {
- kit = readdirSync(scope).find((d) => d.startsWith('kit-'));
- } catch {
- /* scope missing */
- }
- if (!kit) {
- console.error('build-icons: no @awesome.me/kit-* installed — skipping (run `npm install` your FA kit first)');
- process.exit(0);
- }
- const spritesDir = resolve(scope, kit, 'icons/sprites');
- const symbols = [];
- const seen = new Set();
- for (const file of readdirSync(spritesDir).filter((f) => f.endsWith('.svg'))) {
- const svg = readFileSync(resolve(spritesDir, file), 'utf8');
- for (const m of svg.matchAll(/<symbol id="([^"]+)"([\s\S]*?)<\/symbol>/g)) {
- const name = m[1];
- if (seen.has(name)) continue; // first style wins on a name clash
- seen.add(name);
- symbols.push(`<symbol id="dw-${name}"${m[2]}</symbol>`);
- }
- }
- symbols.sort();
- const sprite =
- '<svg xmlns="http://www.w3.org/2000/svg" style="display:none" aria-hidden="true">\n' +
- symbols.join('\n') +
- '\n</svg>\n';
- writeFileSync('icons.svg', sprite);
- console.log(`build-icons: wrote icons.svg — ${symbols.length} icons from ${kit}`);
|