let serve_html = async (env, pathname) => { // read HTML file let data try { data = await env.site.min_html_cache.get(pathname) } catch (err) { if (!(err instanceof Error) || err.code !== 'ENOENT') throw err return false } // try to extract title and body match = data.toString().match(/^([^<]*)<\/title><script src="scripts\/prettify\/prettify\.js"><\/script><script src="scripts\/prettify\/lang-css\.js"><\/script><!--\[if lt IE 9\]>\n <script src="\/\/html5shiv\.googlecode\.com\/svn\/trunk\/html5\.js"><\/script>\n <!\[endif\]--><link type="text\/css" rel="stylesheet" href="styles\/prettify-tomorrow\.css"><link type="text\/css" rel="stylesheet" href="styles\/jsdoc-default\.css"><\/head><body>([^]*)<\/body><\/html>\n?$/) //console.log('match', match) if (match === null) { // not found, just serve the HTML as fallback env.site.serve(env, 200, data, 'jsdoc.dir.jst') return true } // insert title and body into our navbar let navbar = await _require('/_lib/navbar.jst') await navbar( env, // head async _out => { title { _out.push(match[1]) } script(src="scripts/prettify/prettify.js") {} script(src="scripts/prettify/lang-css.js") {} link(type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css") {} link(type="text/css" rel="stylesheet" href="/css/jsdoc-default.css") {} }, // body async _out => { div.jsdoc { _out.push(match[2]) } }, // scripts async _out => {} ) return true; } return async (env, pathname, components) => { if ( components.length === 1 && components[0].slice(-5) === '.html' && await serve_html(env, `${pathname}/${components[0]}`) ) return return /*await*/ env.site.serve_path(env, pathname, components) }