Skip to content

Commit

Permalink
don't apply logoColor param to multi-coloured logos (#2889)
Browse files Browse the repository at this point in the history
  • Loading branch information
chris48s authored and paulmelnikow committed Jan 29, 2019
1 parent efdb9f3 commit daa06c2
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
3 changes: 3 additions & 0 deletions lib/load-logos.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@ function loadLogos() {
// filename is eg, github.svg
const svg = fs.readFileSync(`${logoDir}/${filename}`).toString()
const base64 = svg2base64(svg)
// logo is monochrome if it only has one fill= statement
const isMonochrome = (svg.match(/fill="(.+?)"/g) || []).length === 1

// eg, github
const name = filename.slice(0, -'.svg'.length).toLowerCase()
logos[name] = {
isMonochrome,
svg,
base64,
}
Expand Down
4 changes: 2 additions & 2 deletions lib/logos.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ function getShieldsIcon({ name, color }) {
return undefined
}

const { svg, base64 } = logos[key]
const { svg, base64, isMonochrome } = logos[key]
const svgColor = toSvgColor(color)
if (svgColor) {
if (svgColor && isMonochrome) {
return svg2base64(svg.replace(/fill="(.+?)"/g, `fill="${svgColor}"`))
} else {
return base64
Expand Down
15 changes: 10 additions & 5 deletions lib/logos.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,18 @@ describe('Logo helpers', function() {
})

test(prepareNamedLogo, () => {
// These two strings are identical except for characters 159-165 which
// differ.
given({ name: 'npm' }).expect(
// NPM uses multiple colors so the color param should be ignored
const npmLogo =
'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA0MCA0MCI+PHBhdGggZD0iTTAgMGg0MHY0MEgwVjB6IiBmaWxsPSIjY2IwMDAwIi8+PHBhdGggZmlsbD0iI2ZmZiIgZD0iTTcgN2gyNnYyNmgtN1YxNGgtNnYxOUg3eiIvPjwvc3ZnPgo='
given({ name: 'npm' }).expect(npmLogo)
given({ name: 'npm', color: 'blue' }).expect(npmLogo)

// dependabot only uses one color so the color param should be respected
given({ name: 'dependabot' }).expect(
'data:image/svg+xml;base64,PHN2ZyB2aWV3Qm94PSIwIDAgMjQgMjQiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgZmlsbD0iI2ZmZiI+PHBhdGggZD0iTTkuNzAyLjc3OHY0LjY0OWgzLjA2OFY2Ljk4SDEuNTI4djcuMjM0SDB2NC42NDloMS41Mjh2My42MTdoMjAuOTQ0di0zLjYxN0gyNHYtNC42NDloLTEuNTI4VjYuOThoLTguMTc0Vi43Nzh6bS0uNTIzIDExLjg3bDEuMDIgMS4wNDQtMy4wNDQgMy4wOTUtMi4wNS0yLjA1IDEuMDItMS4wNDUgMS4wMyAxLjAzMnptOC42OTcgMGwxLjAxOCAxLjA0NC0zLjA2OCAzLjA5NS0yLjAzNy0yLjA1IDEuMDE5LTEuMDQ1IDEuMDE4IDEuMDMyeiIvPjwvc3ZnPg=='
)
given({ name: 'npm', color: 'blue' }).expect(
'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA0MCA0MCI+PHBhdGggZD0iTTAgMGg0MHY0MEgwVjB6IiBmaWxsPSIjMDA3ZWM2Ii8+PHBhdGggZmlsbD0iIzAwN2VjNiIgZD0iTTcgN2gyNnYyNmgtN1YxNGgtNnYxOUg3eiIvPjwvc3ZnPgo='
given({ name: 'dependabot', color: 'blue' }).expect(
'data:image/svg+xml;base64,PHN2ZyB2aWV3Qm94PSIwIDAgMjQgMjQiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgZmlsbD0iIzAwN2VjNiI+PHBhdGggZD0iTTkuNzAyLjc3OHY0LjY0OWgzLjA2OFY2Ljk4SDEuNTI4djcuMjM0SDB2NC42NDloMS41Mjh2My42MTdoMjAuOTQ0di0zLjYxN0gyNHYtNC42NDloLTEuNTI4VjYuOThoLTguMTc0Vi43Nzh6bS0uNTIzIDExLjg3bDEuMDIgMS4wNDQtMy4wNDQgMy4wOTUtMi4wNS0yLjA1IDEuMDItMS4wNDUgMS4wMyAxLjAzMnptOC42OTcgMGwxLjAxOCAxLjA0NC0zLjA2OCAzLjA5NS0yLjAzNy0yLjA1IDEuMDE5LTEuMDQ1IDEuMDE4IDEuMDMyeiIvPjwvc3ZnPg=='
)

it('preserves color if light logo on dark background', function() {
Expand Down
2 changes: 1 addition & 1 deletion logo/superuser.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit daa06c2

Please sign in to comment.