#!/usr/bin/env python3 import glob import os import re import sys import yaml def get_all_pages(): return [file for file in glob.glob("gdb/*.md") if not file.endswith("/index.md")] def fix_web_path(page): return '/' + page[:-3] def parse_page_data(page): with open(page) as fd: return next(yaml.safe_load_all(fd)) def most_appropriate_title(data): return data.get("linkTitle") or data['title'] def traverse_siblings(pages, start, sibling='next'): page = start while page in pages: yield page page = pages[page]['siblings'].get(sibling) def create_intro_toc(pages, start, offset=2, file=sys.stdout): for num, page in enumerate(traverse_siblings(pages, start)): data = pages[page] title = most_appropriate_title(data) print(f"{num + offset}. [{title}]({page})\n", file=file) def overwrite_info_toc(pages, start, offset=2): old_name = "gdb/index.md" new_name = "gdb/.index.new" with open(old_name) as orig: with open(new_name, 'w') as new: found = False for line in orig: if found and '{title}', file=file) def overwrite_navbar(pages, start): old_name = "_gdb-menu.hbs" new_name = ".gdb-menu.new" with open(old_name) as orig: with open(new_name, 'w') as new: found = False for line in orig: if found and '