diff --git a/scripts/gen_centered_graph.py b/scripts/gen_centered_graph.py index 6806e1a..fb825b7 100644 --- a/scripts/gen_centered_graph.py +++ b/scripts/gen_centered_graph.py @@ -6,11 +6,15 @@ import os @ops_cache.cache -def gen(headline_id, graph): +def gen(headline_id, graph, doc_to_headline_remapping): reference_node = headline_id linked_from_internal = set() g = copy.deepcopy(graph) + + if 'id:' + reference_node in doc_to_headline_remapping: + reference_node = doc_to_headline_remapping['id:' + reference_node].split(':', 1)[1] + centered_graph = { reference_node: g[reference_node] } for l in g[reference_node]['links']: lt = l['target'] @@ -28,6 +32,9 @@ def gen(headline_id, graph): new_nodes = False removed = set() for k, v in g.items(): + if 'id:' + k in doc_to_headline_remapping: + k = doc_to_headline_remapping['id:' + k].split(':', 1)[1] + for link in v["links"]: if link["target"].startswith("id:"): link["target"] = link["target"][3:] @@ -68,6 +75,9 @@ def gen(headline_id, graph): # One more round for the rest, not requiring "in" for k, v in g.items(): + if 'id:' + k in doc_to_headline_remapping: + k = doc_to_headline_remapping['id:' + k].split(':', 1)[1] + backlinked = False for link in v["links"]: if link["target"].startswith("id:"): diff --git a/scripts/generate.py b/scripts/generate.py index c9d7b15..252efc8 100644 --- a/scripts/generate.py +++ b/scripts/generate.py @@ -310,6 +310,7 @@ def regen_all(src_top, dest_top, *, docs=None, db=None): endpath = os.path.join(dest_top, main_headline.doc.id + ".node.html") with open(endpath, "wt") as f: f.write(render_as_document(main_headline, main_headline.doc, headlineLevel=0, graph=full_graph_info, + doc_to_headline_remapping=doc_to_headline_remapping, title=org_rw.token_list_to_plaintext(main_headline.title.contents))) # Render all headlines @@ -319,6 +320,7 @@ def regen_all(src_top, dest_top, *, docs=None, db=None): # Render HTML with open(endpath, "wt") as f: f.write(render_as_document(headline, headline.doc, headlineLevel=0, graph=full_graph_info, + doc_to_headline_remapping=doc_to_headline_remapping, title=org_rw.token_list_to_plaintext(headline.title.contents))) files_generated += 1 @@ -326,6 +328,7 @@ def regen_all(src_top, dest_top, *, docs=None, db=None): index_endpath = os.path.join(dest_top, "index.html") with open(index_endpath, "wt") as f: f.write(render_as_document(headline, headline.doc, headlineLevel=0, graph=full_graph_info, + doc_to_headline_remapping=doc_to_headline_remapping, title=org_rw.token_list_to_plaintext(headline.title.contents))) files_generated += 1 @@ -653,7 +656,7 @@ def render_inline(tree, f, headline, graph): return ''.join(acc) -def render_as_document(headline, doc, headlineLevel, graph, title): +def render_as_document(headline, doc, headlineLevel, graph, title, doc_to_headline_remapping): if isinstance(headline.parent, org_rw.Headline): topLevelHeadline = headline.parent while isinstance(topLevelHeadline.parent, org_rw.Headline): @@ -676,7 +679,9 @@ def render_as_document(headline, doc, headlineLevel, graph, title): """ else: - return as_document(render(headline, doc, graph=graph, headlineLevel=headlineLevel), title, render_toc(doc)) + return as_document(render(headline, doc, graph=graph, headlineLevel=headlineLevel, + doc_to_headline_remapping=doc_to_headline_remapping), + title, render_toc(doc)) def render_toc(doc): acc = ['