Upgrade to nick_site commit f981fa57, adds alerts and inactive sidebar option
[ndcode_site.git] / jsdoc.dir.jst
1 let serve_html = async (env, pathname) => {
2   // read HTML file
3   let data
4   try {
5     data = await env.site.min_html_cache.get(pathname)
6   }
7   catch (err) {
8     if (!(err instanceof Error) || err.code !== 'ENOENT')
9       throw err
10     return false
11   }
12
13   // try to extract title and body
14   match = data.toString().match(/^<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><title>([^<]*)<\/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?$/)
15   //console.log('match', match)
16   if (match === null) {
17     // not found, just serve the HTML as fallback
18     env.site.serve(env, 200, data, 'jsdoc.dir.jst')
19     return true
20   }
21
22   // insert title and body into our navbar
23   let navbar = await _require('/_lib/navbar.jst')
24   await navbar(
25     env,
26     // head
27     async _out => {
28       title {
29         _out.push(match[1])
30       }
31       script(src="scripts/prettify/prettify.js") {}
32       script(src="scripts/prettify/lang-css.js") {}
33       link(type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css") {}
34       link(type="text/css" rel="stylesheet" href="/css/jsdoc-default.css") {}
35     },
36     // body
37     async _out => {
38       div.jsdoc {
39         _out.push(match[2])
40       }
41     },
42     // scripts
43     async _out => {}
44   )
45   return true;
46 }
47
48 return async (env, pathname, components) => {
49   if (
50     components.length === 1 &&
51     components[0].slice(-5) === '.html' &&
52     await serve_html(env, `${pathname}/${components[0]}`)
53   )
54     return
55   return /*await*/ env.site.serve_path(env, pathname, components)
56 }