Skip to content

Commit 0537065

Browse files
committed
vimhelp: Better header/footer and metadata on the web page
Add support for specifying the version and commit on the command line. The footer will now show something that's more specific to MacVim, while still leaving attribution for vimhelp with a link. It will show the timestamp for generation time and the commit the docs were generated from, so that a viewer can know easily whether the docs are up-to-date, which it should be unless CI broke. The navigation menu on top and bottom now also has a "MacVim reference" to quickly navigate to `gui_mac.txt`, since that's likely the reason for someone browsing this to begin with (instead of vanilla Vim's documentation).
1 parent e505034 commit 0537065

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

vimhelp/scripts/h2h.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,14 @@ def main():
5252
choices=("light", "dark"),
5353
help="Color theme (default: OS-native)",
5454
)
55+
parser.add_argument(
56+
"--version",
57+
help="The version of Vim this document was generated from",
58+
)
59+
parser.add_argument(
60+
"--commit",
61+
help="The commit of Vim this document was generated from",
62+
)
5563
parser.add_argument(
5664
"--no-tags",
5765
"-T",
@@ -99,14 +107,14 @@ def run(args):
99107

100108
if not args.no_tags and (tags_file := args.in_dir / "tags").is_file():
101109
print("Processing tags file...")
102-
h2h = VimH2H(mode=mode, project=args.project, tags=tags_file.read_text())
110+
h2h = VimH2H(mode=mode, project=args.project, version=args.version, commit=args.commit, tags=tags_file.read_text())
103111
faq = args.in_dir / "vim_faq.txt"
104112
if faq.is_file():
105113
print("Processing FAQ tags...")
106114
h2h.add_tags(faq.name, faq.read_text())
107115
else:
108116
print("Initializing tags...")
109-
h2h = VimH2H(mode=mode, project=args.project)
117+
h2h = VimH2H(mode=mode, project=args.project, version=args.version, commit=args.commit)
110118
for infile in args.in_dir.iterdir():
111119
if infile.suffix == ".txt":
112120
h2h.add_tags(infile.name, infile.read_text())

vimhelp/templates/page.html

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ <h1>{{project.name}} help files</h1>
5050
{{theme_switcher}}
5151
</div>
5252
<p>This is an HTML version of the <a href="{{project.url}}" target="_blank" rel="noopener noreferrer">{{project.name}}</a> help pages{% if version %}, current as of {{project.name}} {{version}}{% endif %}.
53-
They are kept up-to-date <a href="https://github.com/c4rlo/vimhelp" target="_blank" rel="noopener noreferrer" class="d">automatically</a>
53+
They are kept up-to-date <a href="https://github.com/macvim-dev/docs" target="_blank" rel="noopener noreferrer" class="d">automatically</a>
5454
from the <a href="{{project.doc_src_url}}" target="_blank" rel="noopener noreferrer" class="d">{{project.name}} source repository</a>.
5555
{% if project.name == "Vim" %}
5656
Also included is the <a href="vim_faq.txt.html">Vim FAQ</a>, kept up to date from its
@@ -65,6 +65,7 @@ <h1>{{project.name}} help files</h1>
6565
{% set sitenavi %}
6666
Quick links:
6767
<a href="{{helptxt}}">help overview</a> &middot;
68+
<a href="gui_mac.txt.html">MacVim reference</a> &middot;
6869
<a href="quickref.txt.html">quick reference</a> &middot;
6970
<a href="usr_toc.txt.html">user manual toc</a> &middot;
7071
<a href="{{helptxt}}#reference_toc">reference manual toc</a>
@@ -110,6 +111,7 @@ <h1>{{project.name}} help files</h1>
110111
</div>
111112
</main>
112113
<p>{{sitenavi}}</p>
113-
<footer>This site is maintained by Carlo Teubner (<i>(my first name) at cteubner dot net</i>).</footer>
114+
<footer>Generated at <span style="font-family:monospace;">{{current_time}}</span>{% if commit %} from commit <a href={{project.repo}}commit/{{commit}} style="font-family:monospace;">{{commit[:8]}}</a>{% endif %}. This documentation is maintained by <a href=https://github.com/macvim-dev>macvim-dev</a>.
115+
The code was modified from <a href=https://github.com/c4rlo/vimhelp>vimhelp</a> (made by Carlo Teubner).</footer>
114116
</body>
115117
</html>

vimhelp/vimhelp/vimh2h.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Translates Vim documentation to HTML
22

3+
from datetime import datetime
34
import flask
45
import functools
56
import html
@@ -155,10 +156,11 @@ def fix_tabs(self, text):
155156

156157

157158
class VimH2H:
158-
def __init__(self, mode="online", project="vim", version=None, tags=None):
159+
def __init__(self, mode="online", project="vim", version=None, tags=None, commit=None):
159160
self._mode = mode
160161
self._project = PROJECTS[project]
161162
self._version = version
163+
self._commit = commit
162164
self._urls = {}
163165
if tags is not None:
164166
for line in RE_NEWLINE.split(tags):
@@ -339,6 +341,8 @@ def to_html(self, filename, contents):
339341
static_dir = "/" if self._mode == "online" else ""
340342
helptxt = "./" if self._mode == "online" else "index.html"
341343

344+
current_time = datetime.utcnow().strftime("%Y-%m-%d %H:%M:%SZ")
345+
342346
return flask.render_template(
343347
"page.html",
344348
mode=self._mode,
@@ -349,6 +353,8 @@ def to_html(self, filename, contents):
349353
helptxt=helptxt,
350354
content=flask.Markup("".join(out)),
351355
sidebar_headings=sidebar_headings,
356+
current_time=current_time,
357+
commit=self._commit,
352358
)
353359

354360

0 commit comments

Comments
 (0)