kopia lustrzana https://github.com/badgen/badgen.net
Migrate badgesize badge to v2
rodzic
075e0801fa
commit
4838f795df
|
@ -0,0 +1,38 @@
|
||||||
|
import got from '../libs/got'
|
||||||
|
import {
|
||||||
|
badgenServe,
|
||||||
|
BadgenServeMeta as Meta,
|
||||||
|
BadgenServeHandlers as Handlers,
|
||||||
|
BadgenServeHandlerArgs as Args
|
||||||
|
} from '../libs/badgen-serve'
|
||||||
|
|
||||||
|
export const meta: Meta = {
|
||||||
|
title: 'Badgesize',
|
||||||
|
examples: {
|
||||||
|
'/badgesize/normal/amio/emoji.json/master/emoji-compact.json': 'normal size',
|
||||||
|
'/badgesize/brotli/amio/emoji.json/master/emoji-compact.json': 'brotli size',
|
||||||
|
'/badgesize/gzip/amio/emoji.json/master/emoji-compact.json': 'gzip size',
|
||||||
|
'/badgesize/normal/https://unpkg.com/snarkdown/dist/snarkdown.js': 'arbitrary url',
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const handlers: Handlers = {
|
||||||
|
'/badgesize/:topic/:path+': handler
|
||||||
|
}
|
||||||
|
|
||||||
|
export default badgenServe(handlers)
|
||||||
|
|
||||||
|
async function handler ({ topic, path }: Args) {
|
||||||
|
const endpoint = `https://img.badgesize.io/${path}.json`
|
||||||
|
const { prettySize, color } = await got(endpoint, {
|
||||||
|
query: {
|
||||||
|
compression: topic === 'normal' ? '' : topic
|
||||||
|
}
|
||||||
|
}).then(res => res.body)
|
||||||
|
|
||||||
|
return {
|
||||||
|
subject: topic === 'normal' ? 'size' : `${topic} size`,
|
||||||
|
status: prettySize,
|
||||||
|
color: color
|
||||||
|
}
|
||||||
|
}
|
2
index.ts
2
index.ts
|
@ -28,7 +28,7 @@ const server = http.createServer(async (req, res) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
// handle endpoints
|
// handle endpoints
|
||||||
const handlerName = badgeHandlers.find(h => req.url!.startsWith(`/${h}`))
|
const handlerName = badgeHandlers.find(h => req.url!.startsWith(`/${h}/`))
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (handlerName) {
|
if (handlerName) {
|
||||||
|
|
|
@ -35,6 +35,7 @@ export const liveBadgeList = [
|
||||||
'lgtm',
|
'lgtm',
|
||||||
'uptime-robot',
|
'uptime-robot',
|
||||||
'xo',
|
'xo',
|
||||||
|
'badgesize',
|
||||||
// utilities
|
// utilities
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue