File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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 )
Original file line number Diff line number Diff line change 44import flask
55import functools
66import html
7+ import json
78import re
89import 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 )]
You can’t perform that action at this time.
0 commit comments