kopia lustrzana https://github.com/badgen/badgen.net
Better icon resolver (fix badgen/badgen#54)
rodzic
fabab708fc
commit
74705c5669
|
@ -15,19 +15,15 @@ export default function (req, res, options: ServeBadgeOptions) {
|
|||
|
||||
const { subject, status, color } = params
|
||||
const { label, list, icon, iconWidth } = query
|
||||
|
||||
const _icon = icons[icon === '' ? subject : icon] || {
|
||||
base64: icon,
|
||||
width: iconWidth
|
||||
}
|
||||
const _icon = resolveIcon(icon === '' ? subject : icon, iconWidth)
|
||||
|
||||
const badge = badgen({
|
||||
subject: typeof label !== 'undefined' ? label : subject,
|
||||
status: list ? String(status).replace(/,/g, ' | ') : String(status),
|
||||
color: query.color || color,
|
||||
style: query.style || process.env.BADGE_STYLE,
|
||||
icon: _icon.base64,
|
||||
iconWidth: _icon.width
|
||||
icon: _icon.src,
|
||||
iconWidth: iconWidth || _icon.width
|
||||
})
|
||||
|
||||
const staleControl = `stale-while-revalidate=604800, stale-if-error=604800`
|
||||
|
@ -37,3 +33,24 @@ export default function (req, res, options: ServeBadgeOptions) {
|
|||
res.statusCode = code
|
||||
res.end(badge)
|
||||
}
|
||||
|
||||
type ResolvedIcon = {
|
||||
src?: string
|
||||
width?: string
|
||||
}
|
||||
|
||||
function resolveIcon (icon: string, width: string): ResolvedIcon {
|
||||
const builtinIcon = icons[icon]
|
||||
if (builtinIcon) {
|
||||
return {
|
||||
src: builtinIcon.base64,
|
||||
width: width || builtinIcon.width
|
||||
}
|
||||
}
|
||||
|
||||
if (icon.startsWith('https://')) {
|
||||
return { src: icon, width }
|
||||
}
|
||||
|
||||
return {}
|
||||
}
|
||||
|
|
Ładowanie…
Reference in New Issue