Created
March 18, 2020 21:10
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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