kopia lustrzana https://github.com/badgen/badgen.net
Add badge: crates
rodzic
4c181809f2
commit
dc6b5bc493
3
index.md
3
index.md
|
|
@ -45,6 +45,9 @@ Available color names:
|
|||
| npm dl/day |  | [/npm/dd/express](/npm/dd/express) |
|
||||
| npm dl/week |  | [/npm/dw/express](/npm/dw/express) |
|
||||
| npm dl/month |  | [/npm/dm/express](/npm/dm/express) |
|
||||
| crates version |  | [/crates/v/regex](/crates/v/regex) |
|
||||
| crates downloads |  | [/crates/d/regex](/crates/d/regex) |
|
||||
| crates downloads latest |  | [/crates/dl/regex](/crates/dl/regex) |
|
||||
| travis |  | [/travis/amio/micro-cors](/travis/amio/micro-cors) |
|
||||
| travis (org) |  | [/travis-org/styfle/packagephobia](/travis-org/styfle/packagephobia) |
|
||||
| circleci |  | [/circleci/github/amio/now-go](/circleci/github/amio/now-go) |
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
const npm = require('./npm.js')
|
||||
|
||||
module.exports = {
|
||||
npm
|
||||
'crates': require('./crates.js'),
|
||||
'npm': require('./npm.js')
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,36 @@
|
|||
const r2 = require('r2')
|
||||
const millify = require('millify')
|
||||
|
||||
module.exports = async function (method, ...args) {
|
||||
const endpoint = `https://crates.io/api/v1/crates/${args[0]}`
|
||||
const meta = await r2(endpoint, {
|
||||
headers: { 'Accept': 'application/json' }
|
||||
}).json
|
||||
|
||||
switch (method) {
|
||||
case 'v':
|
||||
return {
|
||||
subject: 'crates',
|
||||
status: 'v' + meta.crate.max_version,
|
||||
color: ''
|
||||
}
|
||||
case 'd':
|
||||
return {
|
||||
subject: 'downloads',
|
||||
status: millify(meta.crate.downloads),
|
||||
color: 'green'
|
||||
}
|
||||
case 'dl':
|
||||
return {
|
||||
subject: 'downloads',
|
||||
status: millify(meta.crate.recent_downloads) + ' latest version',
|
||||
color: 'green'
|
||||
}
|
||||
default:
|
||||
return {
|
||||
subject: 'crates',
|
||||
status: 'unknown',
|
||||
color: 'grey'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -5,9 +5,9 @@ module.exports = serveMarked('index.md', {
|
|||
preset: 'merri',
|
||||
inlineCSS: `
|
||||
table { border-spacing: 0 }
|
||||
td { padding: 0 1em 0 0; white-space: nowrap }
|
||||
td img { height: 20px }
|
||||
td a { font: 14px/14px monospace; vertical-align: top }
|
||||
td { padding: 0 1em 0 0; white-space: nowrap; vertical-align: middle }
|
||||
td img { height: 20px; position: relative; top: 2px }
|
||||
td a { font: 14px/14px monospace }
|
||||
`,
|
||||
trackingGA: 'UA-4646421-14'
|
||||
})
|
||||
|
|
|
|||
Ładowanie…
Reference in New Issue