kopia lustrzana https://github.com/badgen/badgen.net
Initial commit
commit
b68f2e6b52
|
@ -0,0 +1 @@
|
||||||
|
node_modules
|
|
@ -0,0 +1,40 @@
|
||||||
|
# Fast badge generating service.
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
`https://badgen.now.sh/badge/:subject/:status/:color`
|
||||||
|
|
||||||
|
- `subject` Text
|
||||||
|
- `status` Text
|
||||||
|
- `color` Color RGB (default '3C1') or Color Preset (`green`, `yellow`, ...see below)
|
||||||
|
|
||||||
|
Color Presets:
|
||||||
|
|
||||||
|

|
||||||
|

|
||||||
|

|
||||||
|

|
||||||
|

|
||||||
|

|
||||||
|

|
||||||
|

|
||||||
|

|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
| Preview | URL |
|
||||||
|
| --- | --- |
|
||||||
|
| | https://badgen.now.sh/badge/chat/on%20gitter/blue |
|
||||||
|
| | https://badgen.now.sh/badge/style/standard/f2a |
|
||||||
|
| | https://badgen.now.sh/badge/stars/★★★★☆ |
|
||||||
|
| | https://badgen.now.sh/badge/license/Apache-2.0/blue |
|
||||||
|
| | https://badgen.now.sh/list/platform/ios,macos,tvos/grey |
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
ISC @ Amio
|
||||||
|
|
||||||
|
[npm-badge]: https://img.shields.io/npm/v/badgen.svg
|
||||||
|
[npm-link]: https://www.npmjs.com/package/badgen
|
||||||
|
[pp-badge]: https://packagephobia.now.sh/badge?p=badgen
|
||||||
|
[pp-link]: https://packagephobia.now.sh/result?p=badgen
|
|
@ -0,0 +1,8 @@
|
||||||
|
{
|
||||||
|
"alias": "badgen",
|
||||||
|
"public": true,
|
||||||
|
"files": [
|
||||||
|
"README.md",
|
||||||
|
"service.js"
|
||||||
|
]
|
||||||
|
}
|
Plik diff jest za duży
Load Diff
|
@ -0,0 +1,22 @@
|
||||||
|
{
|
||||||
|
"name": "badgen-service",
|
||||||
|
"private": true,
|
||||||
|
"description": "Badge generating service",
|
||||||
|
"author": "Amio <amio.cn@gmail.com>",
|
||||||
|
"license": "ISC",
|
||||||
|
"scripts": {
|
||||||
|
"lint": "standard",
|
||||||
|
"start": "node service.js",
|
||||||
|
"predeploy": "now rm badgen --safe -y -T badgen",
|
||||||
|
"deploy": "now -T badgen --public && now -T badgen alias"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@amio/micro-cors": "^0.2.0",
|
||||||
|
"badgen": "^0.2.0",
|
||||||
|
"find-my-way": "^1.14.0",
|
||||||
|
"lru-cache": "^4.1.3"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"standard": "^11.0.1"
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,40 @@
|
||||||
|
const http = require('http')
|
||||||
|
const cors = require('@amio/micro-cors')()
|
||||||
|
const router = require('find-my-way')()
|
||||||
|
const badgen = require('badgen')
|
||||||
|
const LRU = require('lru-cache')
|
||||||
|
|
||||||
|
const cache = new LRU({ max: 1000 })
|
||||||
|
|
||||||
|
function serveBadge (req, res, params) {
|
||||||
|
res.writeHead(200, { 'Content-Type': 'image/svg+xml;charset=utf-8' })
|
||||||
|
|
||||||
|
const cached = cache.get(req.url)
|
||||||
|
if (cached) {
|
||||||
|
res.end(cached)
|
||||||
|
} else {
|
||||||
|
const created = badgen(params)
|
||||||
|
cache.set(req.url, created)
|
||||||
|
res.end(created)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function serveListBadge (req, res, params) {
|
||||||
|
const { subject, status, color } = params
|
||||||
|
serveBadge(req, res, { subject, status: status.replace(/,/g, ' | '), color })
|
||||||
|
}
|
||||||
|
|
||||||
|
function redirect (req, res) {
|
||||||
|
res.writeHead(302, { 'Location': 'https://amio.github.io/badgen' })
|
||||||
|
res.end()
|
||||||
|
}
|
||||||
|
|
||||||
|
router.get('/badge/:subject/:status', serveBadge)
|
||||||
|
router.get('/badge/:subject/:status/:color', serveBadge)
|
||||||
|
router.get('/list/:subject/:status', serveListBadge)
|
||||||
|
router.get('/list/:subject/:status/:color', serveListBadge)
|
||||||
|
router.get('/', redirect)
|
||||||
|
|
||||||
|
const handler = cors((req, res) => router.lookup(req, res))
|
||||||
|
const server = http.createServer(handler)
|
||||||
|
server.listen(3000)
|
Ładowanie…
Reference in New Issue