Skip to content

Commit 416109d

Browse files
committed
vimhelp: Add ability to export a tags.json file
This allows us to query the tags directly, and can potentially set up redirect and also client-side tag searching.
1 parent 9c3d5bb commit 416109d

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

vimhelp/scripts/h2h.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@ def main():
6666
action="store_true",
6767
help="Ignore any tags file, always recreate tags from scratch",
6868
)
69+
parser.add_argument(
70+
"--output-tags-json",
71+
"-J",
72+
action="store_true",
73+
help="Output a tags.json file, used for client-side search (when not using online version)",
74+
)
6975
parser.add_argument(
7076
"--profile", "-P", action="store_true", help="Profile performance"
7177
)
@@ -140,6 +146,14 @@ def run(args):
140146
f.write(prelude)
141147
f.write(html)
142148

149+
if args.output_tags_json:
150+
print("Processing tags.json...")
151+
json = h2h.gen_tags_json()
152+
out_filename = "tags.json"
153+
if args.out_dir is not None:
154+
with (args.out_dir / out_filename).open("w") as f:
155+
f.write(json)
156+
143157
if args.out_dir is not None:
144158
print("Symlinking static files...")
145159
static_dir_rel = os.path.relpath(root_path / "static", args.out_dir)

vimhelp/vimhelp/vimh2h.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import flask
55
import functools
66
import html
7+
import json
78
import re
89
import urllib.parse
910

@@ -234,6 +235,11 @@ def xform(c):
234235
def prelude(theme):
235236
return flask.render_template("prelude.html", theme=theme)
236237

238+
def gen_tags_json(self):
239+
obj = {tag: links.href(False) for (tag, links) in self._urls.items()}
240+
return json.dumps(obj, sort_keys=True)
241+
return out
242+
237243
def to_html(self, filename, contents):
238244
is_help_txt = filename == "help.txt"
239245
lines = [line.rstrip("\r\n") for line in RE_NEWLINE.split(contents)]

0 commit comments

Comments
 (0)