kopia lustrzana https://github.com/badgen/badgen.net
badge: add tidelift subscription badge (#391)
rodzic
40958d3368
commit
a337d4656d
|
@ -0,0 +1,36 @@
|
|||
import got from '../libs/got'
|
||||
import { basename, extname } from 'path'
|
||||
import { createBadgenHandler, PathArgs } from '../libs/create-badgen-handler'
|
||||
|
||||
const TIDELIFT_BADGE_URL = 'https://tidelift.com/badges/package/'
|
||||
|
||||
const client = got.extend({ prefixUrl: TIDELIFT_BADGE_URL })
|
||||
|
||||
export default createBadgenHandler({
|
||||
title: 'Tidelift',
|
||||
examples: {
|
||||
'/tidelift/npm/minimist': 'subscription',
|
||||
'/tidelift/npm/got': 'subscription'
|
||||
},
|
||||
handlers: {
|
||||
'/tidelift/:platform/:name': handler
|
||||
}
|
||||
})
|
||||
|
||||
async function handler ({ platform, name }: PathArgs) {
|
||||
const resp = await client.get(`${platform}/${name}`, { followRedirect: false })
|
||||
// this shouldn't happen, but in case it happens
|
||||
if (!resp.headers.location) {
|
||||
throw new Error(`Unknown Tidelift status: ${platform}/${name}`)
|
||||
}
|
||||
const { pathname } = new URL(resp.headers.location)
|
||||
const [status, color] = decodeURIComponent(basename(pathname, extname(pathname)))
|
||||
.split('-')
|
||||
.filter(Boolean)
|
||||
|
||||
return {
|
||||
subject: 'tidelift',
|
||||
status,
|
||||
color
|
||||
}
|
||||
}
|
|
@ -50,6 +50,7 @@ export const liveBadgeList = [
|
|||
'opencollective',
|
||||
'keybase',
|
||||
'twitter',
|
||||
'tidelift',
|
||||
'runkit',
|
||||
'https',
|
||||
]
|
||||
|
|
Ładowanie…
Reference in New Issue