Files
shields/lib/load-simple-icons.js
Caleb Cartwright 956f2e0584 update simple-icons to v5 with by-name lookup backwards compatibility (#6591)
* deps: update simple-icons to v5 in BC manner

* fix: handling of overlapping titles

Co-authored-by: repo-ranger[bot] <39074581+repo-ranger[bot]@users.noreply.github.com>
2021-06-12 19:51:28 +00:00

44 lines
1.7 KiB
JavaScript

'use strict'
const originalSimpleIcons = require('simple-icons')
const { svg2base64 } = require('./svg-helpers')
function loadSimpleIcons() {
const simpleIcons = {}
// As of v5 the exported keys are the svg slugs
// Historically, Shields has supported logo specification via
// name, name with spaces replaced by hyphens, and partially slugs
// albeit only in cases where the slug happened to match one of those.
// For backwards compatibility purposes we now support all three, but
// do not broadcast the support for by-title references due to our strong
// preference to steer users towards using the actual slugs.
// https://github.com/badges/shields/pull/6591
// https://github.com/badges/shields/issues/4273
Object.keys(originalSimpleIcons).forEach(key => {
const icon = originalSimpleIcons[key]
const title = icon.title.toLowerCase()
const legacyTitle = title.replace(/ /g, '-')
icon.base64 = {
default: svg2base64(icon.svg.replace('<svg', `<svg fill="#${icon.hex}"`)),
light: svg2base64(icon.svg.replace('<svg', `<svg fill="whitesmoke"`)),
dark: svg2base64(icon.svg.replace('<svg', `<svg fill="#333"`)),
}
// There are a few instances where multiple icons have the same title
// (e.g. 'Hive'). If a by-title reference we generate for
// backwards compatibility collides with a proper slug from Simple Icons
// then do nothing, so that the proper slug will always map to the correct icon.
if (!(title in originalSimpleIcons)) {
simpleIcons[title] = icon
}
if (!(legacyTitle in originalSimpleIcons)) {
simpleIcons[legacyTitle] = icon
}
simpleIcons[key] = icon
})
return simpleIcons
}
module.exports = loadSimpleIcons