pull/3/head
Amio 2018-05-30 11:13:32 +08:00
rodzic 6638258a61
commit df5ee531ae
3 zmienionych plików z 28 dodań i 2 usunięć

20
README.md 100644
Wyświetl plik

@ -0,0 +1,20 @@
# badgen
Fast, handcraft, pure JavaScript badge generator.
## Usage
### Micro Service
https://badgen.now.sh/badge/:subject/:status/:color
- `subject` Text
- `status` Text
- `color` RGB color (default '4C1')
![](https://badgen.now.sh/badge/build/passing)
![](https://badgen.now.sh/badge/style/standard/f2a)
### As npm package
```npm install badgen```

Wyświetl plik

@ -6,11 +6,11 @@ module.exports = function ({subject, status, color = '4C1'}) {
const charWidth = 7.3 const charWidth = 7.3
const sbTextWidth = subject.length * charWidth const sbTextWidth = subject.length * charWidth
const sbRectWidth = sbTextWidth + 12 const sbRectWidth = sbTextWidth + 10
const sbTextCenter = sbRectWidth / 2 const sbTextCenter = sbRectWidth / 2
const stTextWidth = status.length * charWidth const stTextWidth = status.length * charWidth
const stRectWidth = stTextWidth + 14 const stRectWidth = stTextWidth + 12
const stTextCenter = sbRectWidth + stRectWidth / 2 - 1 const stTextCenter = sbRectWidth + stRectWidth / 2 - 1
const width = sbRectWidth + stRectWidth const width = sbRectWidth + stRectWidth

Wyświetl plik

@ -7,8 +7,14 @@ function generate (req, res, params) {
res.end(badgen(params)) res.end(badgen(params))
} }
const readme = require('fs').readFileSync('./README.md', 'utf-8')
function serveReadme (req, res) {
res.end(readme)
}
router.get('/badge/:subject/:status', generate) router.get('/badge/:subject/:status', generate)
router.get('/badge/:subject/:status/:color', generate) router.get('/badge/:subject/:status/:color', generate)
router.get('/', serveReadme)
const server = http.createServer((req, res) => router.lookup(req, res)) const server = http.createServer((req, res) => router.lookup(req, res))
server.listen(3000) server.listen(3000)