mirror of
https://github.com/lucide-icons/lucide.git
synced 2026-11-17 14:28:25 +00:00
* docs(static): remove broken <img> sprite fragment example Symbols in the sprite only render through <use>, so sprite.svg#name in an <img> tag shows nothing. Point readers to the per-icon SVG files for <img> usage instead. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01G9u8FfpNbRB7XQ9kggfSA1 * feat(lucide-static): add icon aliases to the SVG sprite Aliases were only written as separate SVG files, so `<use href="#home" />` did not work with the sprite. Each alias is now added as a symbol that references the original icon's symbol with a nested `<use>`, instead of duplicating its elements. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01G9u8FgapYRzb6uRJnZpW7N * Adjusted documentation --------- Co-authored-by: Claude <noreply@anthropic.com>
55 lines
1.8 KiB
TypeScript
55 lines
1.8 KiB
TypeScript
import fs from 'fs';
|
|
import path from 'path';
|
|
|
|
import { readSvgDirectory, getCurrentDirPath } from '@lucide/helpers';
|
|
import readSvgs from './readSvgs.mts';
|
|
import generateSprite from './generateSprite.mts';
|
|
import generateIconNodes from './generateIconNodes.mts';
|
|
import copyIcons from './copyIcons.mts';
|
|
|
|
import pkg from '../package.json' with { type: 'json' };
|
|
|
|
const createDirectory = (dir: string) => {
|
|
if (!fs.existsSync(dir)) {
|
|
fs.mkdirSync(dir);
|
|
}
|
|
};
|
|
|
|
const currentDir = getCurrentDirPath(import.meta.url);
|
|
|
|
const PACKAGE_DIR = path.resolve(currentDir, '../');
|
|
const ICONS_DIR = path.join(PACKAGE_DIR, '../../icons');
|
|
const LIB_DIR = path.join(PACKAGE_DIR, 'lib');
|
|
const ICON_MODULE_DIR = path.join(LIB_DIR, 'icons');
|
|
|
|
const license = `@license ${pkg.name} v${pkg.version} - ${pkg.license}`;
|
|
|
|
createDirectory(LIB_DIR);
|
|
createDirectory(ICON_MODULE_DIR);
|
|
|
|
const svgFiles = await readSvgDirectory(ICONS_DIR);
|
|
const svgs = await readSvgs(svgFiles, ICONS_DIR);
|
|
|
|
const aliases = (await Promise.all(
|
|
(await readSvgDirectory(ICONS_DIR, '.json')).map(async (metadataFile) => {
|
|
const filePath = path.join(ICONS_DIR, metadataFile);
|
|
const fileContent = await fs.promises.readFile(filePath, 'utf-8');
|
|
const { aliases }: {aliases: undefined | (string | { name: string })[]} = JSON.parse(fileContent);
|
|
if (!aliases?.length) return [];
|
|
const svgName = path.basename(metadataFile, '.json');
|
|
const svg = svgs.find((s) => s.name === svgName);
|
|
if (!svg) return [];
|
|
return aliases.map(alias => ({
|
|
...svg,
|
|
name: typeof alias === 'string' ? alias : alias.name,
|
|
aliasOf: svgName,
|
|
}));
|
|
})
|
|
)).flat();
|
|
|
|
await Promise.all([
|
|
generateSprite(svgs, aliases, PACKAGE_DIR, license),
|
|
generateIconNodes(svgs, PACKAGE_DIR),
|
|
copyIcons([...svgs, ...aliases], PACKAGE_DIR, license),
|
|
]);
|