Skip to content

Instantly share code, notes, and snippets.

@tigt
Created March 18, 2020 21:10
Show Gist options
  • Star 75 You must be signed in to star a gist
  • Fork 7 You must be signed in to fork a gist
  • Save tigt/86b25ce970e46370dd61339380e2d6bd to your computer and use it in GitHub Desktop.
Save tigt/86b25ce970e46370dd61339380e2d6bd to your computer and use it in GitHub Desktop.
Creates an SVG string that can be used as a favicon across different Git branches. Actually getting this into the browser is sadly project-specific.
const { execSync } = require('child_process')
const { createHash } = require('crypto')
const invertColor = require('invert-color')
const branchName = execSync('git rev-parse --abbrev-ref HEAD')
const hash = createHash('sha256')
hash.update(branchName)
const color = '#' + hash.digest().toString('hex').substring(0, 6)
const invertedColor = invertColor(color, true)
module.exports = `<svg viewBox="0 0 64 64" font-size="64" font-family="monospace,monospace" xmlns="http://www.w3.org/2000/svg">
<rect width="64" height="64" fill="${color}"/>
<text y="64" textLength="64" lengthAdjust="spacingAndGlyphs"
fill="${invertedColor}">${branchName.substring(0, 4)}</text>
</svg>`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment