Sunsetting Shields custom logos (#10347)
* Sunsetting Shields custom logos * Reinstate info to contribute to SimpleIcons * Mention that no changes are required
This commit is contained in:
committed by
GitHub
parent
67deddb8a9
commit
1e4c8f54d7
@@ -1,36 +0,0 @@
|
||||
import fs from 'fs'
|
||||
import path from 'path'
|
||||
import { fileURLToPath } from 'url'
|
||||
import { svg2base64 } from './svg-helpers.js'
|
||||
|
||||
function loadLogos() {
|
||||
// Cache svg logos from disk in base64 string
|
||||
const logos = {}
|
||||
const logoDir = path.join(
|
||||
path.dirname(fileURLToPath(import.meta.url)),
|
||||
'..',
|
||||
'logo',
|
||||
)
|
||||
const logoFiles = fs.readdirSync(logoDir)
|
||||
logoFiles.forEach(filename => {
|
||||
if (filename[0] === '.') {
|
||||
return
|
||||
}
|
||||
// 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,
|
||||
}
|
||||
})
|
||||
return logos
|
||||
}
|
||||
|
||||
export default loadLogos
|
||||
29
lib/logos.js
29
lib/logos.js
@@ -6,9 +6,7 @@ import {
|
||||
} from '../badge-maker/lib/color.js'
|
||||
import coalesce from '../core/base-service/coalesce.js'
|
||||
import { svg2base64, getIconSize, resetIconPosition } from './svg-helpers.js'
|
||||
import loadLogos from './load-logos.js'
|
||||
import loadSimpleIcons from './load-simple-icons.js'
|
||||
const logos = loadLogos()
|
||||
const simpleIcons = loadSimpleIcons()
|
||||
|
||||
// for backwards-compatibility with deleted logos
|
||||
@@ -19,6 +17,7 @@ const logoAliases = {
|
||||
scrutinizer: 'scrutinizer-ci',
|
||||
stackoverflow: 'stack-overflow',
|
||||
tfs: 'azure-devops',
|
||||
travis: 'travisci',
|
||||
}
|
||||
const lightThreshold = 0.4
|
||||
const darkThreshold = 0.6
|
||||
@@ -59,24 +58,6 @@ function decodeDataUrlFromQueryParam(value) {
|
||||
return isDataUrl(maybeDataUrl) ? maybeDataUrl : undefined
|
||||
}
|
||||
|
||||
function getShieldsIcon({ name, color }) {
|
||||
if (!(name in logos)) {
|
||||
return undefined
|
||||
}
|
||||
|
||||
const { svg, base64, isMonochrome } = logos[name]
|
||||
const svgColor = toSvgColor(color)
|
||||
if (svgColor) {
|
||||
if (isMonochrome) {
|
||||
return svg2base64(svg.replace(/fill="(.+?)"/g, `fill="${svgColor}"`))
|
||||
} else {
|
||||
return undefined
|
||||
}
|
||||
} else {
|
||||
return base64
|
||||
}
|
||||
}
|
||||
|
||||
function getSimpleIconStyle({ icon, style }) {
|
||||
const { hex } = icon
|
||||
if (style !== 'social' && brightness(normalizeColor(hex)) <= lightThreshold) {
|
||||
@@ -93,7 +74,7 @@ function getSimpleIconStyle({ icon, style }) {
|
||||
// badge. If `size` is not 'auto', the icon will be displayed at its original.
|
||||
// https://github.com/badges/shields/pull/9191
|
||||
function getSimpleIcon({ name, color, style, size }) {
|
||||
const key = name === 'travis' ? 'travis-ci' : name.replace(/ /g, '-')
|
||||
const key = name.replace(/ /g, '-')
|
||||
|
||||
if (!(key in simpleIcons)) {
|
||||
return undefined
|
||||
@@ -134,10 +115,7 @@ function prepareNamedLogo({ name, color, style, size }) {
|
||||
name = logoAliases[name]
|
||||
}
|
||||
|
||||
return (
|
||||
getShieldsIcon({ name, color }) ||
|
||||
getSimpleIcon({ name, color, style, size })
|
||||
)
|
||||
return getSimpleIcon({ name, color, style, size })
|
||||
}
|
||||
|
||||
function makeLogo(defaultNamedLogo, overrides) {
|
||||
@@ -159,7 +137,6 @@ export {
|
||||
isDataUrl,
|
||||
decodeDataUrlFromQueryParam,
|
||||
prepareNamedLogo,
|
||||
getShieldsIcon,
|
||||
getSimpleIcon,
|
||||
makeLogo,
|
||||
}
|
||||
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user