Skip to content

Commit

Permalink
deps: update simple-icons to v5 in BC manner
Browse files Browse the repository at this point in the history
  • Loading branch information
calebcartwright committed Jun 11, 2021
1 parent b0384f4 commit 80f8a0c
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 25 deletions.
6 changes: 4 additions & 2 deletions doc/logos.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

![](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

Expand Down
10 changes: 6 additions & 4 deletions frontend/components/usage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -335,10 +335,12 @@ export default function Usage({ baseUrl }: { baseUrl: string }): JSX.Element {
>
simple-icons
</a>
. 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:{' '}
<StyledCode>?logo=visual-studio-code</StyledCode>)
. Simple-icons are referenced using icon slugs which can be
found on the simple-icons site or in the
<a href="https://github.com/simple-icons/simple-icons/blob/develop/slugs.md">
slugs.md file
</a>{' '}
in the simple-icons repository.
</span>
}
key="logo"
Expand Down
29 changes: 19 additions & 10 deletions lib/load-simple-icons.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,27 @@ 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('<svg', `<svg fill="#${simpleIcons[k].hex}"`)
),
light: svg2base64(
simpleIcons[k].svg.replace('<svg', `<svg fill="whitesmoke"`)
),
dark: svg2base64(simpleIcons[k].svg.replace('<svg', `<svg fill="#333"`)),
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"`)),
}
simpleIcons[key] = icon
simpleIcons[title] = icon
simpleIcons[legacyTitle] = icon
})
return simpleIcons
}
Expand Down
6 changes: 5 additions & 1 deletion lib/load-simple-icons.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ describe('loadSimpleIcons', function () {
})

it('normalizes icon keys', function () {
// original key in the simple-icons is 'Linux Foundation'
// As of v5 of simple-icons the slug and exported key is `linuxfoundation`
// with a name of `Linux Foundation`, so ensure we support both as well
// as the legacy mapping of `linux-foundation` for backwards compatibility.
expect(simpleIcons).to.include.key('linuxfoundation')
expect(simpleIcons).to.include.key('linux foundation')
expect(simpleIcons).to.include.key('linux-foundation')
})

Expand Down
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
"query-string": "^7.0.0",
"request": "~2.88.2",
"semver": "~7.3.5",
"simple-icons": "4.25.0",
"simple-icons": "5.1.0",
"webextension-store-meta": "^1.0.3",
"xmldom": "~0.6.0",
"xpath": "~0.0.32"
Expand Down

0 comments on commit 80f8a0c

Please sign in to comment.