{sections_html}
#!/usr/bin/env python3 """Combine all numbered page files into a single index.html.""" import os import re def build_index(title, DIR): # Collect numbered pages, sorted numerically page_nums = sorted( int(m.group(1)) for f in os.listdir(DIR) if (m := re.match(r'^(\d+)\.html$', f)) ) def read_page(n): with open(os.path.join(DIR, f'{n}.html'), encoding='utf-8') as f: content = f.read() content = re.sub(r'[ \t]*]+>\n?', '', content) return content.strip() sections = [(n, read_page(n)) for n in page_nums] sidebar_items = '\n '.join( f'
' for n in page_nums ) sections_html = '\n\n '.join( f'