Skip to content

Commit

Permalink
Keep the icon order consistent with JSON data file (#223)
Browse files Browse the repository at this point in the history
  • Loading branch information
LitoMore authored Jan 4, 2025
1 parent 887b6f4 commit 57b286e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
2 changes: 1 addition & 1 deletion preview/html/testpage.pug
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ body

p.grid
each icon in icons
i.si.si--color(class='si-' + icon.slug, title=icon.name)
i.si.si--color(class='si-' + icon.slug, title=icon.title)

p.paragraph
| An icon like #[i.si.si--color.si-github(title='Github')] inside a paragraph.
Expand Down
8 changes: 7 additions & 1 deletion scripts/build-testpage.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import fs from 'node:fs';
import path from 'node:path';
import pug from 'pug';
import * as icons from 'simple-icons/icons';
import { getIconsData, titleToSlug } from 'simple-icons/sdk';
import { fileURLToPath } from 'node:url';

const __dirname = path.dirname(fileURLToPath(import.meta.url));
Expand All @@ -16,6 +16,12 @@ const ROOT_DIR = path.resolve(__dirname, '..');
const INPUT_FILE = path.join(ROOT_DIR, 'preview', 'html', 'testpage.pug');
const OUTPUT_FILE = path.join(ROOT_DIR, 'preview', 'testpage.html');

const iconsData = await getIconsData();
const icons = iconsData.map((icon) => ({
title: icon.title,
slug: icon.slug || titleToSlug(icon.title),
}));

pug.renderFile(INPUT_FILE, { icons }, (renderError, html) => {
if (renderError) {
throw renderError;
Expand Down
11 changes: 9 additions & 2 deletions scripts/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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++),
);
Expand All @@ -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)
Expand Down

0 comments on commit 57b286e

Please sign in to comment.