diff --git a/package.json b/package.json index ab1259a..a5e0630 100644 --- a/package.json +++ b/package.json @@ -8,6 +8,7 @@ "scripts": { "lint": "standard", "bench": "node bench/index.js", + "preview": "node test/serve-preview.js", "test": "tap test/*.spec.js --reporter spec", "start": "node service.js", "predeploy": "now rm badgen --safe -y -T badgen", diff --git a/test/PREVIEW.md b/test/PREVIEW.md index 71c10a9..82f3321 100644 --- a/test/PREVIEW.md +++ b/test/PREVIEW.md @@ -19,3 +19,4 @@ |![](http://localhost:3000/chat/gitter/purple) | http://localhost:3000/chat/gitter/purple | |![](http://localhost:3000/style/standard/f2a) | http://localhost:3000/style/standard/f2a | |![](http://localhost:3000/license/Apache-2.0/blue) | http://localhost:3000/license/Apache-2.0/blue | +|![](http://localhost:3000/Language/Swift%203.0.1/orange) | http://localhost:3000/Language/Swift%203.0.1/orange | diff --git a/test/serve.js b/test/serve-preview.js similarity index 79% rename from test/serve.js rename to test/serve-preview.js index 578daed..b43ab67 100644 --- a/test/serve.js +++ b/test/serve-preview.js @@ -1,12 +1,16 @@ const http = require('http') const path = require('path') +const qs = require('querystring') const serveMarked = require('serve-marked') const badgen = require('..') // @example // http://localhost:3000/npm/v1.2.3 const serveBadge = (req, res) => { - const [ subject, status, color ] = req.url.split('/').filter(Boolean) + const [ subject, status, color ] = req.url.split('/') + .filter(Boolean) + .map(s => qs.unescape(s)) + res.writeHead(200, { 'Content-Type': 'image/svg+xml;charset=utf-8' }) res.end(badgen({subject, status, color})) } @@ -29,9 +33,7 @@ const serveIndex = serveMarked(md, { http.createServer((req, res) => { switch (req.url) { - case '/': - return serveIndex(req, res) - default: - return serveBadge(req, res) + case '/': return serveIndex(req, res) + default: return serveBadge(req, res) } }).listen(3000)