1
0
mirror of https://github.com/tabler/tabler-icons.git synced 2025-03-20 02:59:52 +01:00

Enhance icon sprite generation: add support for multiple sprite files and improve SVG handling (#1314)

This commit is contained in:
Paweł Kuna 2025-01-29 21:44:38 +01:00 committed by GitHub
parent 07859b0962
commit 183fc904ab
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -3,26 +3,36 @@ import { getAllIcons } from '../../.build/helpers.mjs'
const icons = getAllIcons(true)
fs.mkdirSync('dist', { recursive: true })
const buildSprite = () => {
let svgContent = ''
Object.entries(icons).forEach(([type, iconsInCategory]) => {
let svgContent = ''
console.log(`Building ${type} sprite...`)
iconsInCategory.forEach(icon => {
console.log(`Adding ${icon.name}...`)
const svgFileContent = icon.content
.replace(/<svg[^>]+>/g, '')
.replace(/<\/svg>/g, '')
.replace(/\n+/g, '')
.replace(/>\s+</g, '><')
.replace('<path stroke="none" d="M0 0h24v24H0z" fill="none"/>', '')
.trim()
svgContent += `<symbol id="tabler-${type == 'outline' ? '' : `${type}-`}${icon.name}" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">${svgFileContent}</symbol>`
svgContent += `<symbol id="tabler-${type == 'outline' ? '' : `${type}-`}${icon.name}" viewBox="0 0 24 24" fill="${type == 'outline' ? 'none' : 'currentColor'}" stroke="${type == 'outline' ? 'currentColor' : 'none'}" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">${svgFileContent}</symbol>`
})
let svg = `<svg xmlns="http://www.w3.org/2000/svg" id="tabler-icons${type == 'outline' ? '' : `-${type}`}"><defs>${svgContent}</defs></svg>`
fs.writeFileSync(`dist/tabler-sprite${type == 'outline' ? '' : `-${type}`}.svg`, svg)
if (type == 'outline') {
fs.writeFileSync(`dist/tabler-sprite-nostroke.svg`, svg.replace(/stroke-width="2"\s/g, ''))
}
})
let svg = `<svg xmlns="http://www.w3.org/2000/svg"><defs>${svgContent}</defs></svg>`
fs.mkdirSync('dist', { recursive: true })
fs.writeFileSync('dist/tabler-sprite.svg', svg)
fs.writeFileSync('dist/tabler-sprite-nostroke.svg', svg.replace(/stroke-width="2"\s/g, ''))
}
buildSprite()