diff --git a/scripts/generate.py b/scripts/generate.py index 0741e9e..b2e0ec2 100644 --- a/scripts/generate.py +++ b/scripts/generate.py @@ -259,6 +259,17 @@ def regen_all(src_top, dest_top, *, docs=None, db=None): if link['target'] in doc_to_headline_remapping: link['target'] = doc_to_headline_remapping[link['target']] + # Remap document ids backlinks to main headlines + for doc_id, main_headline_id in doc_to_headline_remapping.items(): + if doc_id.startswith('id:'): + doc_id = doc_id[len('id:'):] + if main_headline_id.startswith('id:'): + main_headline_id = main_headline_id[len('id:'):] + for backlink in backlink_graph.get(doc_id, []): + if main_headline_id not in backlink_graph: + backlink_graph[main_headline_id] = set() + backlink_graph[main_headline_id].add(backlink) + # Render docs after we've built the graph # Render main headlines full_graph_info = { "nodes": graph, "backlinks": backlink_graph, "main_headlines": main_headlines_by_path }