From e4b654e2dcc7df7203c4f7a6aef1a477d92b94d0 Mon Sep 17 00:00:00 2001 From: LitoMore Date: Sun, 29 Dec 2024 01:15:43 +0800 Subject: [PATCH] Keep the icon order consistent with data JSON --- scripts/build.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/scripts/build.js b/scripts/build.js index 20176fa..2574e5d 100644 --- a/scripts/build.js +++ b/scripts/build.js @@ -10,6 +10,7 @@ import fsSync, { promises as fs } from 'node:fs'; import path from 'node:path'; import punycode from 'punycode/punycode.js'; import * as simpleIcons from 'simple-icons/icons'; +import { getIconsData, titleToSlug } from 'simple-icons/sdk'; import svg2ttf from 'svg2ttf'; import SVGPath from 'svgpath'; import ttf2eot from 'ttf2eot'; @@ -46,13 +47,19 @@ const cssDecodeUnicode = (value) => { return value.replace('&#x', '\\').replace(';', '').toLowerCase(); }; +const icons = await getIconsData(); +const iconKeys = icons.map((icon) => { + const slug = icon.slug ?? titleToSlug(icon.title); + return 'si' + slug.at(0).toUpperCase() + slug.slice(1); +}); + const buildSimpleIconsSvgFontFile = async () => { const usedUnicodes = []; const unicodeHexBySlug = []; let startUnicode = 0xea01; let glyphsContent = ''; - for (const si in simpleIcons) { + for (const key of iconKeys) { const nextUnicode = punycode.ucs2.decode( String.fromCodePoint(startUnicode++), ); @@ -63,7 +70,7 @@ const buildSimpleIconsSvgFontFile = async () => { throw Error(`Unicodes must be unique. Found '${unicodeString}' repeated`); } - const icon = simpleIcons[si]; + const icon = simpleIcons[key]; const verticalTransformedPath = SVGPath(icon.path) .translate(0, -24) .scale(50, -50)