kopia lustrzana https://github.com/badgen/badgen.net
badge: Add CTAN service (#455)
rodzic
edd4551b0d
commit
a37cceb2e5
|
@ -0,0 +1,41 @@
|
|||
import got from '../libs/got'
|
||||
import { version, versionColor } from '../libs/utils'
|
||||
import { createBadgenHandler, PathArgs } from '../libs/create-badgen-handler'
|
||||
|
||||
const CTAN_API_URL = 'https://ctan.org/json/2.0/'
|
||||
|
||||
const client = got.extend({ prefixUrl: CTAN_API_URL, timeout: 3500 })
|
||||
|
||||
export default createBadgenHandler({
|
||||
title: 'CTAN',
|
||||
examples: {
|
||||
'/ctan/v/latexindent': 'version',
|
||||
'/ctan/license/latexdiff': 'license'
|
||||
},
|
||||
handlers: {
|
||||
'/ctan/:topic<v|license>/:pkg': handler,
|
||||
}
|
||||
})
|
||||
|
||||
async function handler ({ topic, pkg }: PathArgs) {
|
||||
const {
|
||||
license,
|
||||
version: versionInfo,
|
||||
} = await client.get(`pkg/${pkg}`).json<any>()
|
||||
const { number: ver } = versionInfo;
|
||||
|
||||
switch (topic) {
|
||||
case 'v':
|
||||
return {
|
||||
subject: 'ctan',
|
||||
status: version(ver),
|
||||
color: versionColor(ver)
|
||||
}
|
||||
case 'license':
|
||||
return {
|
||||
subject: 'license',
|
||||
status: license || 'unknown',
|
||||
color: 'green'
|
||||
}
|
||||
}
|
||||
}
|
|
@ -29,6 +29,7 @@ export const liveBadgeList = [
|
|||
'cocoapods',
|
||||
'haxelib',
|
||||
'opam',
|
||||
'ctan',
|
||||
'scoop',
|
||||
'winget',
|
||||
'f-droid',
|
||||
|
|
Ładowanie…
Reference in New Issue