Upgrade to nick_site commit f981fa57, adds alerts and inactive sidebar option
[ndcode_site.git] / sphinx.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 head before/after stylesheet and body
14   match = data.toString().match(/^<!DOCTYPE html><html xmlns="http:\/\/www\.w3\.org\/1999\/xhtml"><head><meta charset="utf-8">([^]*)<link rel="stylesheet" href="_static\/classic\.css" type="text\/css"><link rel="stylesheet" href="_static\/pygments\.css" type="text\/css"><script id="documentation_options" data-url_root="\.\/" src="_static\/documentation_options\.js"><\/script><script src="_static\/jquery\.js"><\/script><script src="_static\/underscore\.js"><\/script><script src="_static\/doctools\.js"><\/script><script src="_static\/language_data\.js"><\/script>(<script src="_static\/searchtools\.js"><\/script>)?([^]*)<\/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, 'sphinx.dir.jst')
19     return true
20   }
21
22   // insert head before/after stylesheet and body into our navbar
23   let navbar = await _require('/_lib/navbar.jst')
24   await navbar(
25     env,
26     // head
27     async _out => {
28       _out.push(match[1])
29       link(type="text/css" rel="stylesheet" href="/css/sphinx/classic.css") {}
30       link(type="text/css" rel="stylesheet" href="/css/sphinx/pygments.css") {}
31       script(id="documentation_options" data-url_root="./" src="/js/sphinx/documentation_options.js") {}
32       script(src="/js/sphinx/jquery.js") {}
33       script(src="/js/sphinx/underscore.js") {}
34       script(src="/js/sphinx/doctools.js") {}
35       script(src="/js/sphinx/language_data.js") {}
36       if (match[2] !== undefined)
37         script(src="/js/sphinx/searchtools.js") {}
38       _out.push(match[3])
39     },
40     // body
41     async _out => {
42       div.sphinx {
43         _out.push(match[4])
44       }
45     },
46     // scripts
47     async _out => {}
48   )
49   return true;
50 }
51
52 return async (env, pathname, components) => {
53   if (
54     components.length === 1 &&
55     components[0].slice(-5) === '.html' &&
56     await serve_html(env, `${pathname}/${components[0]}`)
57   )
58     return
59   return /*await*/ env.site.serve_path(env, pathname, components)
60 }