11from __future__ import annotations
22
3- import collections
4- import json
53import os .path
6- from typing import Any
74
85import mako .lookup
96import markupsafe
2926)
3027
3128
32- ALL_TEMPLATES = [
33- filename for filename in os .listdir ('.' )
34- if filename .endswith ('.mako' ) and filename != 'base.mako'
35- ]
36-
37-
38- def get_env () -> dict [str , Any ]:
29+ def index_body () -> markupsafe .Markup :
3930 body_parts = []
4031 for title , filename in SECTIONS :
4132 div_id , _ = os .path .splitext (os .path .basename (filename ))
@@ -50,30 +41,22 @@ def get_env() -> dict[str, Any]:
5041 f'</div>\n ' ,
5142 ),
5243 )
53- body = markupsafe .Markup ().join (body_parts )
44+ return markupsafe .Markup ().join (body_parts )
5445
55- all_hooks = json .loads (
56- open ('all-hooks.json' ).read (),
57- object_pairs_hook = collections .OrderedDict ,
58- )
59- all_types = {
60- hook_type
61- for properties in all_hooks .values ()
62- for hook_type in (
63- properties [0 ].get ('types' , []) + properties [0 ].get ('types_or' , [])
64- )
65- }
66- return {'all_hooks' : all_hooks , 'all_types' : all_types , 'body' : body }
46+
47+ def hooks_body () -> markupsafe .Markup :
48+ with open ('sections/hooks.md' ) as f :
49+ return md (f .read ())
6750
6851
6952def main () -> int :
70- env = get_env ()
71- for template in ALL_TEMPLATES :
72- template_name , _ = os . path . splitext ( template )
73- env [ 'template_name' ] = template_name
74- with open (f' { template_name } .html' , 'w' ) as html_file :
75- template_obj = template_lookup .get_template (template )
76- html_file .write (template_obj .render (** env ))
53+ with open ( 'index.html' , 'w' ) as f :
54+ tmpl = template_lookup . get_template ( 'index.mako' )
55+ f . write ( tmpl . render ( body = index_body (), template_name = 'index' ) )
56+
57+ with open ('hooks .html' , 'w' ) as f :
58+ tmpl = template_lookup .get_template ('hooks.mako' )
59+ f .write (tmpl .render (body = hooks_body (), template_name = 'hooks' ))
7760 return 0
7861
7962
0 commit comments