From df5ee531ae3da9922d8c3802ec06bd5fa161ae56 Mon Sep 17 00:00:00 2001 From: Amio Date: Wed, 30 May 2018 11:13:32 +0800 Subject: [PATCH] Add README.md --- README.md | 20 ++++++++++++++++++++ index.js | 4 ++-- service.js | 6 ++++++ 3 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..752a398 --- /dev/null +++ b/README.md @@ -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``` diff --git a/index.js b/index.js index b089d84..94d6662 100644 --- a/index.js +++ b/index.js @@ -6,11 +6,11 @@ module.exports = function ({subject, status, color = '4C1'}) { const charWidth = 7.3 const sbTextWidth = subject.length * charWidth - const sbRectWidth = sbTextWidth + 12 + const sbRectWidth = sbTextWidth + 10 const sbTextCenter = sbRectWidth / 2 const stTextWidth = status.length * charWidth - const stRectWidth = stTextWidth + 14 + const stRectWidth = stTextWidth + 12 const stTextCenter = sbRectWidth + stRectWidth / 2 - 1 const width = sbRectWidth + stRectWidth diff --git a/service.js b/service.js index a6db99b..96db76d 100644 --- a/service.js +++ b/service.js @@ -7,8 +7,14 @@ function generate (req, res, 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/:color', generate) +router.get('/', serveReadme) const server = http.createServer((req, res) => router.lookup(req, res)) server.listen(3000)