From 956f2e058461ed26c599f97f836c6002bd5a0d1d Mon Sep 17 00:00:00 2001 From: Caleb Cartwright Date: Sat, 12 Jun 2021 14:51:28 -0500 Subject: [PATCH] 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> --- doc/logos.md | 6 ++++-- frontend/components/usage.tsx | 10 +++++---- lib/load-simple-icons.js | 39 ++++++++++++++++++++++++++--------- lib/load-simple-icons.spec.js | 15 +++++++++++++- package-lock.json | 14 ++++++------- package.json | 2 +- 6 files changed, 61 insertions(+), 25 deletions(-) diff --git a/doc/logos.md b/doc/logos.md index 8fcbffbfea..ff07f9f014 100644 --- a/doc/logos.md +++ b/doc/logos.md @@ -4,9 +4,11 @@ ### SimpleIcons -We support a wide range of logos via [SimpleIcons][]. They can be referenced by name e.g: +We support a wide range of logos via [SimpleIcons][]. They should be referenced by the logo slug e.g: -![](https://img.shields.io/npm/v/npm.svg?logo=javascript) - https://img.shields.io/npm/v/npm.svg?logo=javascript +![](https://img.shields.io/npm/v/npm.svg?logo=nodedotjs) - https://img.shields.io/npm/v/npm.svg?logo=nodedotjs + +The set of Simple Icon slugs can be found in the [slugs.md](https://github.com/simple-icons/simple-icons/blob/develop/slugs.md) file in the Simple Icons repository. NB - the Simple Icons site and that slugs.md page may at times contain new icons that haven't yet been pulled into the Shields.io runtime. More information on how and when we incorporate icon updates can be found [here](https://github.com/badges/shields/discussions/5369). ### Shields logos diff --git a/frontend/components/usage.tsx b/frontend/components/usage.tsx index ed4523f1ce..e553780703 100644 --- a/frontend/components/usage.tsx +++ b/frontend/components/usage.tsx @@ -335,10 +335,12 @@ export default function Usage({ baseUrl }: { baseUrl: string }): JSX.Element { > simple-icons - . Simple-icons are referenced using names as they appear on the - simple-icons site. If the name includes spaces, replace them - with dashes (e.g:{' '} - ?logo=visual-studio-code) + . Simple-icons are referenced using icon slugs which can be + found on the simple-icons site or in the + + slugs.md file + {' '} + in the simple-icons repository. } key="logo" diff --git a/lib/load-simple-icons.js b/lib/load-simple-icons.js index 976573d411..86f9b8e356 100644 --- a/lib/load-simple-icons.js +++ b/lib/load-simple-icons.js @@ -5,18 +5,37 @@ 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 k = key.toLowerCase().replace(/ /g, '-') - simpleIcons[k] = originalSimpleIcons[key] - simpleIcons[k].base64 = { - default: svg2base64( - simpleIcons[k].svg.replace('