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