Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep the icon order consistent with data JSON #223

Merged
merged 2 commits into from
Jan 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading