kopia lustrzana https://github.com/badgen/badgen.net
Migrate crates badge to v2
rodzic
ad018077b7
commit
a47f7671ac
|
@ -0,0 +1,55 @@
|
||||||
|
import got from '../libs/got'
|
||||||
|
import { millify, version, versionColor } from '../libs/utils'
|
||||||
|
import {
|
||||||
|
badgenServe,
|
||||||
|
BadgenServeMeta as Meta,
|
||||||
|
BadgenServeHandlers as Handlers,
|
||||||
|
BadgenServeHandlerArgs as Args
|
||||||
|
} from '../libs/badgen-serve'
|
||||||
|
|
||||||
|
export const meta: Meta = {
|
||||||
|
title: 'Rust Crates',
|
||||||
|
examples: {
|
||||||
|
'/crates/v/regex': 'version',
|
||||||
|
'/crates/d/regex': 'downloads',
|
||||||
|
'/crates/dl/regex': 'downloads (latest version)',
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const handlers: Handlers = {
|
||||||
|
'/crates/:topic/:name': handler
|
||||||
|
}
|
||||||
|
|
||||||
|
export default badgenServe(handlers)
|
||||||
|
|
||||||
|
async function handler ({topic, pkg}: Args) {
|
||||||
|
const endpoint = `https://crates.io/api/v1/crates/${pkg}`
|
||||||
|
const { crate } = await got(endpoint).then(res => res.body)
|
||||||
|
|
||||||
|
switch (topic) {
|
||||||
|
case 'v':
|
||||||
|
return {
|
||||||
|
subject: 'crates.io',
|
||||||
|
status: version(crate.max_version),
|
||||||
|
color: versionColor(crate.max_version)
|
||||||
|
}
|
||||||
|
case 'd':
|
||||||
|
return {
|
||||||
|
subject: 'downloads',
|
||||||
|
status: millify(crate.downloads),
|
||||||
|
color: 'green'
|
||||||
|
}
|
||||||
|
case 'dl':
|
||||||
|
return {
|
||||||
|
subject: 'downloads',
|
||||||
|
status: millify(crate.recent_downloads) + ' latest version',
|
||||||
|
color: 'green'
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
return {
|
||||||
|
subject: 'crates',
|
||||||
|
status: 'unknown topic',
|
||||||
|
color: 'grey'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -12,6 +12,7 @@ const liveBadgeExampleList = [
|
||||||
'david',
|
'david',
|
||||||
'packagephobia',
|
'packagephobia',
|
||||||
'bundlephobia',
|
'bundlephobia',
|
||||||
|
'crates',
|
||||||
'amo',
|
'amo',
|
||||||
'apm',
|
'apm',
|
||||||
'homebrew',
|
'homebrew',
|
||||||
|
|
Ładowanie…
Reference in New Issue