Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

automatically show light or dark logos when using simple-icons #2833

Merged
merged 5 commits into from
Jan 23, 2019

Conversation

chris48s
Copy link
Member

closes #2431
refs #2510

Implements @RedSparr0w 's suggestion from #2431 (comment)

light logo:


dark logo:


medium logo:


if we're overriding colorA, meh.. the user can work it out 🤷‍♂️

@shields-ci
Copy link

shields-ci commented Jan 21, 2019

Messages
📖 ✨ Thanks for your contribution to Shields, @chris48s!

Generated by 🚫 dangerJS against ab208b1

@paulmelnikow paulmelnikow added the core Server, BaseService, GitHub auth label Jan 21, 2019
Copy link
Member

@paulmelnikow paulmelnikow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an awesome example of a good default (with customization when you need it), and I'm excited to ship it. I left a comment about a higher-bracket test, and another one about optimization because this code gets run a lot.

lib/logos.js Outdated
const svgColor = toSvgColor(color)
const svgColor =
toSvgColor(color) ||
toSvgColor(getSimpleIconColor({ icon: simpleIcons[key], style }))
if (svgColor) {
return svg2base64(svg.replace('<svg', `<svg fill="${svgColor}"`))
} else {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The way this is written it looks like we will never end up here. i.e. we will always recompute the svg + the base64 transform.

Should we precompute the whitesmoke and #333 versions when the logos are loaded, instead?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The way this is written it looks like we will never end up here. i.e. we will always recompute the svg + the base64 transform.

Yeah, think this may be the case.

Should we precompute the whitesmoke and #333 versions when the logos are loaded, instead?

Good idea, it should save a quite a bit of resources in the long run.

and then we would just need to update the replace to something like:

svg.replace(/fill=".+?"/, `fill="${svgColor}"`);

Although it could probably be done in a separate PR later on if its too much hassle.

lib/logos.js Outdated
}

function hexToRgb(hex) {
const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you move the regex declaration outside the function?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see this regex being used outside of this function.
Would it be better to keep it in here until its needed elsewhere?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think moving it outside is a performance optimisation. It gets declared once when we start the server process instead of redefining it on every function call

given({ icon: { hex: '004880' }, style: 'social' }).expect('004880') // dark logo, light background
given({ icon: { hex: '00AFF0' }, style: undefined }).expect('00AFF0') // medium logo, dark background
given({ icon: { hex: '00AFF0' }, style: 'social' }).expect('00AFF0') // medium logo, light background
})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good to have a couple higher-level tests of this functionality. Perhaps you could call add a third test for prepareNamedLogo() with a result you've checked, or else a regular unit test that turns the base64 back into svg and checks that it includes whitesmoke.

This is "unconversion" code I wrote for #2473:

const logoSvg = Buffer.from(
  getShieldsIcon({ name: 'github' }).replace('data:image/svg+xml;base64,', ''),
  'base64'
).toString('ascii')

@RedSparr0w
Copy link
Member

👍 Nice work, This looks good to me!

Just to clarify that if colorA is changed:

light logo: will keep default color

medium logo: will keep default color

dark logo: will be changed to whitesmoke color, unless logoColor specified

@paulmelnikow paulmelnikow temporarily deployed to shields-staging-pr-2833 January 22, 2019 22:09 Inactive
@chris48s
Copy link
Member Author

Just to clarify that if colorA is changed:
...

Hmm. Good point. The reason that's happening is because if the style is anything other than "social", we're assuming the background is the default and applying the "dark background" logic. Do you think we should explicitly pass through overrides.colorA so we can ensure we use the simple-icons default in that case?

@RedSparr0w
Copy link
Member

RedSparr0w commented Jan 22, 2019

It should be fine the way you have done it, I think most people would probably find it more unexpected if the logo color suddenly changed when they changed colorA?

Edit: Although, It would make it harder for people to find the brand/default color.

@chris48s
Copy link
Member Author

Although, It would make it harder for people to find the brand/default color.

I think the brandColor=true idea you had in #2431 would probably be a better way to deal with this

Copy link
Member

@paulmelnikow paulmelnikow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the tests!

@paulmelnikow paulmelnikow merged commit eaa64a8 into badges:master Jan 23, 2019
@shields-deployment
Copy link

This pull request was merged to master branch. This change is now waiting for deployment, which will usually happen within a few days. Stay tuned by joining our #ops channel on Discord!

After deployment, changes are copied to gh-pages branch:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Server, BaseService, GitHub auth
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Automatically show light or dark logos depending on left color
4 participants