OILS / doctools / doc_html.py View on Github | oilshell.org

107 lines, 35 significant
1#!/usr/bin/env python2
2"""
3doc_html.py
4"""
5from __future__ import print_function
6
7import cgi
8import sys
9
10# Used by html_head.py
11JS_FMT = '<script type="text/javascript" src="%s"></script>\n'
12
13CSS_FMT = '<link rel="stylesheet" type="text/css" href="%s" />\n'
14
15def Header(meta, f, draft_warning=False):
16 css_files = [x for x in meta['css_files'].split() if x]
17
18 meta['css_links'] = ''.join(CSS_FMT % url for url in css_files)
19
20 # CSS links are NOT escaped
21 meta['title'] = cgi.escape(meta['title'])
22
23 # NOTE: 'meta viewport' so it's not small on mobile browsers
24 f.write('''\
25<!DOCTYPE html>
26<html>
27 <head>
28 <meta name="viewport" content="width=device-width, initial-scale=1">
29 <title>%(title)s</title>
30 %(css_links)s
31 </head>
32 <body class="%(body_css_class)s">
33 <p id="home-link">
34''' % meta)
35
36 compact_title = meta.get('compact_title')
37 if compact_title:
38 f.write('''\
39<span id="compact-title">%(title)s</span>
40''' % meta)
41
42 f.write('''\
43 <span id="why-sponsor"><a href="/why-sponsor.html">Why Sponsor Oils?</a></span> |
44 <a href="https://github.com/oilshell/oil/blob/master/%(repo_url)s" id="source-link">source</a> |
45''' % meta)
46
47 if meta.get('all_docs_url') != '-':
48 f.write('''\
49 <span id="all-docs"><a href="%(all_docs_url)s">all docs</a>
50 for <span id="version-in-header">version %(oil_version)s</span></span> |
51''' % meta)
52 elif meta.get('version_url') != '-':
53 # The doc/ URL needs to go back
54 f.write('''\
55 <a href="..">version %(oil_version)s</a> |
56''' % meta)
57
58 f.write('''\
59 <a href="/releases.html">all versions</a> |
60 <a href="/">oilshell.org</a>
61''' % meta)
62
63 if draft_warning:
64 f.write('''\
65 <span id="draft-warning" style="visibility: hidden;"></span>
66
67 <script type="text/javascript">
68 function showWarning(el) {
69 el.innerHTML = '<br/>This is a DRAFT. Latest docs are at <a href="/release/latest/doc/">/release/latest/doc/</a> ';
70 el.style.visibility = "visible";
71 }
72 function removeVersion(el) {
73 el.innerHTML = '<a href=".">drafts</a>';
74 }
75
76 var url = window.location.href;
77 if (url.indexOf('/preview/') === -1) {
78 console.log("Not a draft");
79 } else {
80 showWarning(document.querySelector('#draft-warning'));
81 removeVersion(document.querySelector('#all-docs'));
82 }
83 </script>
84''')
85
86 f.write('</p>')
87
88 if 'in_progress' in meta:
89 f.write('''\
90 <p style="background-color: mistyrose; font-size: large;
91 text-align: center; padding: 1em;">
92
93 <b>Warning: Work in progress!</b> Leave feedback on <a
94 href="https://oilshell.zulipchat.com">Zulip</a> or <a
95 href="https://github.com/oilshell/oil/issues">Github</a> if you'd like
96 this doc to be updated.
97 </p>
98''')
99
100
101def Footer(meta, f):
102 f.write('''\
103 <hr/>
104 <div id="build-timestamp"><i>Generated on %(build_timestamp)s</i></div>
105 </body>
106</html>
107''' % meta)