diff --git a/scripts/generate.py b/scripts/generate.py index e300386..ae8e554 100644 --- a/scripts/generate.py +++ b/scripts/generate.py @@ -182,6 +182,7 @@ def regen_all(src_top, dest_top, *, docs=None, db=None): # Build graph graph = {} + backlink_graph = {} for headline in all_headlines: links = [] headline_links = list(headline.get_links()) @@ -216,6 +217,19 @@ def regen_all(src_top, dest_top, *, docs=None, db=None): "target": headline.parent.id, "relation": "in" }) + for backlink in links: + if 'relation' in backlink and backlink['relation'] == 'in': + continue + + target = backlink['target'] + if target.startswith('id:'): + target = target[len('id:'):] + + if target not in backlink_graph: + backlink_graph[target] = set() + + backlink_graph[target].add(headline.id) + graph[headline.id] = { "title": org_rw.org_rw.token_list_to_plaintext(headline.title.contents).strip(), "links": links, @@ -247,7 +261,7 @@ def regen_all(src_top, dest_top, *, docs=None, db=None): # Render docs after we've built the graph # Render main headlines - full_graph_info = { "nodes": graph, "main_headlines": main_headlines_by_path } + full_graph_info = { "nodes": graph, "backlinks": backlink_graph, "main_headlines": main_headlines_by_path } for _docpath, main_headline in main_headlines_by_path.items(): if main_headline.doc.id: endpath = os.path.join(dest_top, main_headline.doc.id + ".node.html") @@ -428,7 +442,6 @@ def render_code_block(element, acc, headline, graph): def render_results_block(element, acc, headline, graph): items = [e.get_raw() for e in element.children] - print(items) content = '\n'.join(items) if len(content.strip()) > 0: render_block(content, acc, _class='results lang-text', is_code=False) @@ -576,6 +589,17 @@ def render_as_document(headline, doc, headlineLevel, graph, title): else: return as_document(render(headline, doc, graph=graph, headlineLevel=headlineLevel), title) +def render_connections(headline_id, content, graph): + if headline_id not in graph['backlinks']: + return + + content.append("