Remap document IDs.
This commit is contained in:
parent
d6c8b9f3db
commit
dee465f6af
@ -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:"):
|
||||
|
@ -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):
|
||||
</html>
|
||||
"""
|
||||
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 = ['<ul class="toc">']
|
||||
@ -704,15 +709,15 @@ def render_toc_headline(headline, acc):
|
||||
|
||||
|
||||
|
||||
def render_connections(headline_id, content, graph):
|
||||
def render_connections(headline_id, content, graph, doc_to_headline_remapping):
|
||||
# if headline_id != 'aa29be89-70e7-4465-91ed-361cf0ce62f2':
|
||||
# return
|
||||
|
||||
logging.info("Generating centered graph for {}".format(headline_id))
|
||||
svg = gen_centered_graph.gen(headline_id, graph['nodes'])
|
||||
svg = gen_centered_graph.gen(headline_id, graph['nodes'], doc_to_headline_remapping)
|
||||
content.append("<div class='connections'>{}</div>".format(svg))
|
||||
|
||||
def render(headline, doc, graph, headlineLevel):
|
||||
def render(headline, doc, graph, headlineLevel, doc_to_headline_remapping):
|
||||
try:
|
||||
dom = headline.as_dom()
|
||||
except:
|
||||
@ -723,10 +728,11 @@ def render(headline, doc, graph, headlineLevel):
|
||||
content = []
|
||||
render_tree(dom, content, headline, graph)
|
||||
if headline.id and headlineLevel == 0:
|
||||
render_connections(headline.id, content, graph)
|
||||
render_connections(headline.id, content, graph, doc_to_headline_remapping=doc_to_headline_remapping)
|
||||
|
||||
for child in headline.children:
|
||||
content.append(render(child, doc, headlineLevel=headlineLevel+1, graph=graph))
|
||||
content.append(render(child, doc, headlineLevel=headlineLevel+1, graph=graph,
|
||||
doc_to_headline_remapping=doc_to_headline_remapping))
|
||||
|
||||
if headline.state is None:
|
||||
state = ""
|
||||
|
Loading…
Reference in New Issue
Block a user