kopia lustrzana https://github.com/badgen/badgen
chore: enhance preview (#16)
* chore: add a port variable and log final url * fix: bad preview uri for case-sensitive systems * chore: live reload of preview changespull/17/head
rodzic
a17df69255
commit
311eda0944
|
@ -7,8 +7,6 @@ const badgen = require('..')
|
||||||
|
|
||||||
const iconDataURI = require('../test/icon-data-uri.js')
|
const iconDataURI = require('../test/icon-data-uri.js')
|
||||||
|
|
||||||
// @example
|
|
||||||
// http://localhost:3000/npm/v1.2.3
|
|
||||||
const serveBadge = (req, res) => {
|
const serveBadge = (req, res) => {
|
||||||
const { pathname, query } = url.parse(req.url)
|
const { pathname, query } = url.parse(req.url)
|
||||||
const { style, icon } = qs.parse(query)
|
const { style, icon } = qs.parse(query)
|
||||||
|
@ -21,35 +19,36 @@ const serveBadge = (req, res) => {
|
||||||
res.end(badgen({ subject, status, color, style, icon: icon && iconDataURI }))
|
res.end(badgen({ subject, status, color, style, icon: icon && iconDataURI }))
|
||||||
}
|
}
|
||||||
|
|
||||||
// @example
|
const md = path.join(__dirname, 'preview.md')
|
||||||
// http://localhost:3000
|
const inlineCSS = `
|
||||||
const md = path.join(__dirname, 'PREVIEW.md')
|
body { color: #333; padding-bottom: 5em; max-width: 800px }
|
||||||
const serveIndex = serveMarked(md, {
|
a { text-decoration: none; color: #06D }
|
||||||
title: 'badgen preview',
|
a:hover { text-decoration: underline }
|
||||||
preset: 'merri',
|
table { border-spacing: 0 }
|
||||||
inlineCSS: `
|
td { padding: 0 1em 0 0; height: 24px; font: 14px/14px sans-serif }
|
||||||
body { color: #333; padding-bottom: 5em; max-width: 800px }
|
td a { font: 14px/14px monospace; vertical-align: top }
|
||||||
a { text-decoration: none; color: #06D }
|
img { height: 30px }
|
||||||
a:hover { text-decoration: underline }
|
`
|
||||||
table { border-spacing: 0 }
|
|
||||||
td { padding: 0 1em 0 0; height: 24px; font: 14px/14px sans-serif }
|
|
||||||
td a { font: 14px/14px monospace; vertical-align: top }
|
|
||||||
img { height: 30px }
|
|
||||||
`
|
|
||||||
})
|
|
||||||
|
|
||||||
const serve404 = (req, res) => {
|
const serve404 = (req, res) => {
|
||||||
res.writeHead(404)
|
res.writeHead(404)
|
||||||
res.end()
|
res.end()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const port = 3000
|
||||||
http.createServer((req, res) => {
|
http.createServer((req, res) => {
|
||||||
switch (req.url) {
|
switch (req.url) {
|
||||||
case '/':
|
case '/':
|
||||||
return serveIndex(req, res)
|
return serveMarked(md, {
|
||||||
|
title: 'badgen preview',
|
||||||
|
preset: 'merri',
|
||||||
|
inlineCSS
|
||||||
|
})(req, res)
|
||||||
case '/favicon.ico':
|
case '/favicon.ico':
|
||||||
return serve404(req, res)
|
return serve404(req, res)
|
||||||
default:
|
default:
|
||||||
return serveBadge(req, res)
|
return serveBadge(req, res)
|
||||||
}
|
}
|
||||||
}).listen(3000)
|
}).listen(port)
|
||||||
|
|
||||||
|
console.log(`Preview served at http://localhost:${port}`)
|
||||||
|
|
Ładowanie…
Reference in New Issue