kopia lustrzana https://github.com/badgen/badgen.net
Serve local markdown as index
rodzic
cc7fc8088b
commit
4ada41e93f
|
@ -190,6 +190,11 @@
|
|||
"integrity": "sha1-r6uWJikQp/M8GaV3WCXGnzTjUMo=",
|
||||
"dev": true
|
||||
},
|
||||
"caseless": {
|
||||
"version": "0.12.0",
|
||||
"resolved": "https://registry.npmjs.org/caseless/-/caseless-0.12.0.tgz",
|
||||
"integrity": "sha1-G2gcIf+EAzyCZUMJBolCDRhxUdw="
|
||||
},
|
||||
"chalk": {
|
||||
"version": "2.4.1",
|
||||
"resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.1.tgz",
|
||||
|
@ -988,6 +993,11 @@
|
|||
"integrity": "sha1-PMWfAAJRlLarLjjbrmaJJWtmBXI=",
|
||||
"dev": true
|
||||
},
|
||||
"is-typedarray": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/is-typedarray/-/is-typedarray-1.0.0.tgz",
|
||||
"integrity": "sha1-5HnICFjfDBsR3dppQPlgEfzaSpo="
|
||||
},
|
||||
"isarray": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz",
|
||||
|
@ -1155,6 +1165,11 @@
|
|||
"integrity": "sha1-Sr6/7tdUHywnrPspvbvRXI1bpPc=",
|
||||
"dev": true
|
||||
},
|
||||
"node-fetch": {
|
||||
"version": "2.1.2",
|
||||
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.1.2.tgz",
|
||||
"integrity": "sha1-q4hOjn5X44qUR1POxwb3iNF2i7U="
|
||||
},
|
||||
"normalize-package-data": {
|
||||
"version": "2.4.0",
|
||||
"resolved": "https://registry.npmjs.org/normalize-package-data/-/normalize-package-data-2.4.0.tgz",
|
||||
|
@ -1415,6 +1430,16 @@
|
|||
"resolved": "https://registry.npmjs.org/pseudomap/-/pseudomap-1.0.2.tgz",
|
||||
"integrity": "sha1-8FKijacOYYkX7wqKw0wa5aaChrM="
|
||||
},
|
||||
"r2": {
|
||||
"version": "2.0.1",
|
||||
"resolved": "https://registry.npmjs.org/r2/-/r2-2.0.1.tgz",
|
||||
"integrity": "sha512-EEmxoxYCe3LHzAUhRIRxdCKERpeRNmlLj6KLUSORqnK6dWl/K5ShmDGZqM2lRZQeqJgF+wyqk0s1M7SWUveNOQ==",
|
||||
"requires": {
|
||||
"caseless": "^0.12.0",
|
||||
"node-fetch": "^2.0.0-alpha.8",
|
||||
"typedarray-to-buffer": "^3.1.2"
|
||||
}
|
||||
},
|
||||
"read-pkg": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/read-pkg/-/read-pkg-2.0.0.tgz",
|
||||
|
@ -1781,6 +1806,14 @@
|
|||
"integrity": "sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c=",
|
||||
"dev": true
|
||||
},
|
||||
"typedarray-to-buffer": {
|
||||
"version": "3.1.5",
|
||||
"resolved": "https://registry.npmjs.org/typedarray-to-buffer/-/typedarray-to-buffer-3.1.5.tgz",
|
||||
"integrity": "sha512-zdu8XMNEDepKKR+XYOXAVPtWui0ly0NtohUscw+UmaHiAWT8hrV1rr//H6V+0DvJ3OQ19S979M0laLfX8rm82Q==",
|
||||
"requires": {
|
||||
"is-typedarray": "^1.0.0"
|
||||
}
|
||||
},
|
||||
"uniq": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/uniq/-/uniq-1.0.1.tgz",
|
||||
|
|
|
@ -14,7 +14,8 @@
|
|||
"@amio/micro-cors": "^0.2.0",
|
||||
"badgen": "^0.2.1",
|
||||
"find-my-way": "^1.14.0",
|
||||
"lru-cache": "^4.1.3"
|
||||
"lru-cache": "^4.1.3",
|
||||
"r2": "^2.0.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"standard": "^11.0.1"
|
||||
|
|
20
service.js
20
service.js
|
@ -1,3 +1,5 @@
|
|||
const fs = require('fs')
|
||||
const r2 = require('r2')
|
||||
const http = require('http')
|
||||
const cors = require('@amio/micro-cors')()
|
||||
const router = require('find-my-way')()
|
||||
|
@ -38,11 +40,27 @@ function cleanCache (req, res) {
|
|||
res.end(`Cleaned ${count}\n${keys}`)
|
||||
}
|
||||
|
||||
function serveMarkdown (file) {
|
||||
let content = fs.readFileSync(file, 'utf-8')
|
||||
r2.post('https://md.now.sh', {
|
||||
json: {
|
||||
text: content,
|
||||
title: 'Badgen - fast badge generator',
|
||||
linkCSS: 'https://cdnjs.cloudflare.com/ajax/libs/github-markdown-css/2.10.0/github-markdown.min.css'
|
||||
}
|
||||
}).text.then(html => (content = html))
|
||||
|
||||
return (req, res) => {
|
||||
res.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8' })
|
||||
res.end(content)
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
router.get('/', serveMarkdown('README.md'))
|
||||
router.get('/clean-cache', cleanCache)
|
||||
|
||||
const handler = cors((req, res) => router.lookup(req, res))
|
||||
|
|
Ładowanie…
Reference in New Issue