Skip to content

Commit

Permalink
fix: handling of overlapping titles
Browse files Browse the repository at this point in the history
  • Loading branch information
calebcartwright committed Jun 12, 2021
1 parent 4cd70c0 commit 32554a2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
14 changes: 12 additions & 2 deletions lib/load-simple-icons.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,19 @@ function loadSimpleIcons() {
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
simpleIcons[title] = icon
simpleIcons[legacyTitle] = icon
})
return simpleIcons
}
Expand Down
9 changes: 9 additions & 0 deletions lib/load-simple-icons.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,13 @@ describe('loadSimpleIcons', function () {
it('excludes "get" function provided by the simple-icons', function () {
expect(simpleIcons).to.not.have.property('get')
})

it('maps overlapping icon titles correctly', function () {
// Both of these icons have the same title: 'Hive', so make sure
// the proper slugs are still mapped to the correct logo
expect(simpleIcons.hive.slug).to.equal('hive')
expect(simpleIcons.hive.title).to.equal('Hive')
expect(simpleIcons.hive_blockchain.slug).to.equal('hive_blockchain')
expect(simpleIcons.hive_blockchain.title).to.equal('Hive')
})
})

0 comments on commit 32554a2

Please sign in to comment.