badge: add tidelift subscription badge (#391)

pull/390/head^2
Dario Vladović 2020-05-20 11:50:47 +02:00 zatwierdzone przez GitHub
rodzic 40958d3368
commit a337d4656d
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
2 zmienionych plików z 37 dodań i 0 usunięć

36
api/tidelift.ts 100644
Wyświetl plik

@ -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
}
}

Wyświetl plik

@ -50,6 +50,7 @@ export const liveBadgeList = [
'opencollective',
'keybase',
'twitter',
'tidelift',
'runkit',
'https',
]