kopia lustrzana https://github.com/badgen/badgen.net
badge(liberapay): add badges for Liberapay (#425)
rodzic
7ddcf20086
commit
27e69bf81d
|
@ -0,0 +1,65 @@
|
|||
import got from '../libs/got'
|
||||
import { createBadgenHandler, PathArgs } from '../libs/create-badgen-handler'
|
||||
|
||||
export default createBadgenHandler({
|
||||
title: 'Liberapay',
|
||||
examples: {
|
||||
'/liberapay/gives/aurelienpierre': 'giving',
|
||||
'/liberapay/receives/GIMP': 'receiving',
|
||||
'/liberapay/patrons/microG': 'patrons count',
|
||||
'/liberapay/goal/Changaco': 'goal progress',
|
||||
},
|
||||
handlers: {
|
||||
'/liberapay/:topic<gives|receives|patrons|goal>/:slug': handler
|
||||
}
|
||||
})
|
||||
|
||||
// https://github.com/badges/shields/blob/master/services/liberapay
|
||||
|
||||
async function handler ({ topic, slug }: PathArgs) {
|
||||
const endpoint = `https://liberapay.com/${slug}/public.json`
|
||||
|
||||
const details = await got(endpoint).json<any>()
|
||||
const receivingLocaleOptions = {
|
||||
style: 'currency',
|
||||
currency: details.giving.currency
|
||||
}
|
||||
const givingLocaleOptions = {
|
||||
style: 'currency',
|
||||
currency: details.receiving.currency
|
||||
}
|
||||
|
||||
let goal = 'not set'
|
||||
if (details.goal) {
|
||||
const goalAmount = parseFloat(details.goal.amount)
|
||||
const receivesAmount = parseFloat(details.receiving.amount)
|
||||
goal = `${Math.round((receivesAmount / goalAmount) * 100)}%`
|
||||
}
|
||||
|
||||
switch (topic) {
|
||||
case 'gives':
|
||||
return {
|
||||
subject: 'gives',
|
||||
status: `${parseFloat(details.giving.amount).toLocaleString('en-US', givingLocaleOptions)}/week`,
|
||||
color: 'yellow'
|
||||
}
|
||||
case 'receives':
|
||||
return {
|
||||
subject: 'receives',
|
||||
status: `${parseFloat(details.receiving.amount).toLocaleString('en-US', receivingLocaleOptions)}/week`,
|
||||
color: 'yellow'
|
||||
}
|
||||
case 'patrons':
|
||||
return {
|
||||
subject: 'patrons',
|
||||
status: details.npatrons,
|
||||
color: 'yellow'
|
||||
}
|
||||
case 'goal':
|
||||
return {
|
||||
subject: 'goal progress',
|
||||
status: goal,
|
||||
color: goal !== 'not set' ? 'yellow' : 'grey'
|
||||
}
|
||||
}
|
||||
}
|
|
@ -60,6 +60,7 @@ export const liveBadgeList = [
|
|||
'runkit',
|
||||
'https',
|
||||
'jenkins',
|
||||
'liberapay'
|
||||
]
|
||||
|
||||
export async function loadBadgeMeta () {
|
||||
|
|
Ładowanie…
Reference in New Issue