mirror of
https://github.com/lucide-icons/lucide.git
synced 2026-11-14 13:58:21 +00:00
fix icon preview comment (#1823)
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import { shuffle, readSvgDirectory, getCurrentDirPath } from './helpers.mjs';
|
||||
import { shuffle, readSvgDirectory, getCurrentDirPath, minifySvg } from './helpers.mjs';
|
||||
|
||||
const currentDir = getCurrentDirPath(import.meta.url);
|
||||
const ICONS_DIR = path.resolve(currentDir, '../icons');
|
||||
@@ -17,11 +17,10 @@ const getImageTagsByFiles = (files, getBaseUrl, width) =>
|
||||
files
|
||||
.map((file) => {
|
||||
const svgContent = fs.readFileSync(path.join(process.cwd(), file), 'utf-8');
|
||||
const strippedAttrsSVG = svgContent
|
||||
.replace(/<svg[^>]*>/, '<svg>')
|
||||
.replaceAll(/\n| {2}|\t/g, '');
|
||||
const strippedAttrsSVG = svgContent.replace(/<svg[^>]*>/, '<svg>')
|
||||
const minifiedSvg = minifySvg(strippedAttrsSVG)
|
||||
|
||||
const base64 = Buffer.from(strippedAttrsSVG).toString('base64');
|
||||
const base64 = Buffer.from(minifiedSvg).toString('base64');
|
||||
const url = getBaseUrl(file);
|
||||
const widthAttr = width ? `width="${width}"` : '';
|
||||
|
||||
|
||||
@@ -208,3 +208,17 @@ export const shuffle = (array) => {
|
||||
}
|
||||
return array;
|
||||
};
|
||||
|
||||
/**
|
||||
* Minifies SVG
|
||||
*
|
||||
* @param {string} string
|
||||
* @returns string
|
||||
*/
|
||||
export function minifySvg(string){
|
||||
return string ? string
|
||||
.replace(/\>[\r\n ]+</g, "><")
|
||||
.replace(/(<.*?>)|\s+/g, (m, $1) => $1 || ' ')
|
||||
.trim()
|
||||
: ""
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user