From 87e4a8aa7d894b57faeec2281304dc80a88d89ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20Mart=C3=ADnez=20Portela?= Date: Wed, 9 Nov 2022 19:53:56 +0100 Subject: [PATCH] Remap document ids backlinks to main headlines. --- scripts/generate.py | 11 +++++++++++ 1 file changed, 11 insertions(+) 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 }