Skip to content

Instantly share code, notes, and snippets.

@dcinzona
Forked from tigt/git-branch-to-favicon.js
Created March 26, 2020 15:51
Show Gist options
  • Save dcinzona/dc3c623caf78ef9c1315d39c63c55a4b to your computer and use it in GitHub Desktop.
Save dcinzona/dc3c623caf78ef9c1315d39c63c55a4b 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