File tree Expand file tree Collapse file tree 2 files changed +20
-0
lines changed Expand file tree Collapse file tree 2 files changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -66,6 +66,12 @@ def main():
66
66
action = "store_true" ,
67
67
help = "Ignore any tags file, always recreate tags from scratch" ,
68
68
)
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
+ )
69
75
parser .add_argument (
70
76
"--profile" , "-P" , action = "store_true" , help = "Profile performance"
71
77
)
@@ -140,6 +146,14 @@ def run(args):
140
146
f .write (prelude )
141
147
f .write (html )
142
148
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
+
143
157
if args .out_dir is not None :
144
158
print ("Symlinking static files..." )
145
159
static_dir_rel = os .path .relpath (root_path / "static" , args .out_dir )
Original file line number Diff line number Diff line change 4
4
import flask
5
5
import functools
6
6
import html
7
+ import json
7
8
import re
8
9
import urllib .parse
9
10
@@ -234,6 +235,11 @@ def xform(c):
234
235
def prelude (theme ):
235
236
return flask .render_template ("prelude.html" , theme = theme )
236
237
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
+
237
243
def to_html (self , filename , contents ):
238
244
is_help_txt = filename == "help.txt"
239
245
lines = [line .rstrip ("\r \n " ) for line in RE_NEWLINE .split (contents )]
You can’t perform that action at this time.
0 commit comments