"use strict"; const fs = require("fs"); const path = require("path"); const iconsDir = path.resolve(__dirname, "svg"); const outFile = path.resolve(__dirname, "gallery.html"); if (!fs.existsSync(iconsDir)) { console.error(`SVG directory not found: ${iconsDir}`); process.exit(1); } const entries = fs.readdirSync(iconsDir, { withFileTypes: true }) .filter(d => d.isFile() && d.name.toLowerCase().endsWith(".svg")) .map(d => ({ name: d.name, size: fs.statSync(path.join(iconsDir, d.name)).size })) .sort((a, b) => a.name.localeCompare(b.name, "zh", { sensitivity: "base", numeric: true })); const empty = entries.filter(e => e.size === 0); const nonEmpty = entries.filter(e => e.size > 0); const escapeHtml = (s) => String(s) .replace(/&/g, "&") .replace(//g, ">") .replace(/\"/g, """) .replace(/'/g, "'"); function renderCard(file, kind) { const display = file.name.replace(/\.svg$/i, ""); const safe = escapeHtml(display); const dataName = display.toLowerCase(); const src = "svg/" + encodeURIComponent(file.name); if (kind === 'empty') { return `\n
\n
\n
${safe}
\n
`; } return `\n
\n
${safe}
\n
${safe}
\n
`; } const rowsNonEmpty = nonEmpty.map(f => renderCard(f, 'icon')).join(""); const rowsEmpty = empty.map(f => renderCard(f, 'empty')).join(""); const html = ` SVG 图标预览

SVG 图标预览

/
${rowsNonEmpty}${rowsEmpty}\n
`; const utf8NoBom = new (require('util').TextEncoder)(); fs.writeFileSync(outFile, html, { encoding: "utf8" }); console.log(`Generated: ${outFile} with ${nonEmpty.length} icons and ${empty.length} empty files`);