import serveMarked from 'serve-marked'
import serve404 from '../libs/serve-404'
import genHelp from '../libs/gen-help'
export default async function (req, res, name) {
const helpMarkdown = genHelp(name)
if (helpMarkdown) {
res.setHeader('Cache-Control', 'public, max-age=86400, s-maxage=604800, stale-while-revalidate=86400')
return serveMarked(helpMarkdown, {
title: `${name} badge | Badgen`,
inlineCSS,
beforeHeadEnd: '',
beforeBodyEnd: helpFooter,
trackingGA: process.env.TRACKING_GA
})(req, res)
}
serve404(req, res)
}
const inlineCSS = `
html, body { scroll-behavior: smooth }
.markdown-body { max-width: 850px }
.markdown-body h1 { margin-bottom: 42px }
li > img { vertical-align: middle; margin: 0.2em 0; font-size: 12px; float: right }
li > img + a { font-family: monospace; font-size: 0.9em }
li > img + a + i { color: #AAA }
h4 a code { color: #333; font-size: 1rem }
h4 a:hover { text-decoration: none !important }
h4 { padding: 4px 0 }
`
const helpFooter = `
`