Fix: render graph.json, a dependency, before node-centered-graph.
This commit is contained in:
parent
49a5ec3df2
commit
3f5ec66c3d
@ -288,6 +288,19 @@ def regen_all(src_top, dest_top, *, docs=None, db=None):
|
||||
backlink_graph[main_headline_id] = set()
|
||||
backlink_graph[main_headline_id].add(backlink)
|
||||
|
||||
# Output graph files
|
||||
graphpath = os.path.join(dest_top, "graph.json")
|
||||
graph_explorer_path = os.path.join(dest_top, "graph.html")
|
||||
with open(graphpath, "wt") as f:
|
||||
json.dump(obj=graph, fp=f, indent=2)
|
||||
graph_explorer_path = os.path.join(dest_top, "graph.html")
|
||||
with open(graph_explorer_path, 'wt') as f:
|
||||
with open(os.path.join(os.path.dirname(os.path.abspath(dest_top)), '..', 'static', 'graph_explorer.html'), 'rt') as template:
|
||||
source = template.read()
|
||||
f.write(source.replace('<!-- REPLACE_THIS_WITH_GRAPH -->',
|
||||
json.dumps(graph)))
|
||||
logging.info("Generated {} files".format(files_generated))
|
||||
|
||||
# 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 }
|
||||
@ -298,7 +311,6 @@ def regen_all(src_top, dest_top, *, docs=None, db=None):
|
||||
f.write(render_as_document(main_headline, main_headline.doc, headlineLevel=0, graph=full_graph_info,
|
||||
title=org_rw.token_list_to_plaintext(main_headline.title.contents)))
|
||||
|
||||
|
||||
# Render all headlines
|
||||
for headline in all_headlines:
|
||||
endpath = os.path.join(dest_top, headline.id + ".node.html")
|
||||
@ -316,18 +328,6 @@ def regen_all(src_top, dest_top, *, docs=None, db=None):
|
||||
title=org_rw.token_list_to_plaintext(headline.title.contents)))
|
||||
files_generated += 1
|
||||
|
||||
# Output graph files
|
||||
graphpath = os.path.join(dest_top, "graph.json")
|
||||
graph_explorer_path = os.path.join(dest_top, "graph.html")
|
||||
with open(graphpath, "wt") as f:
|
||||
json.dump(obj=graph, fp=f, indent=2)
|
||||
graph_explorer_path = os.path.join(dest_top, "graph.html")
|
||||
with open(graph_explorer_path, 'wt') as f:
|
||||
with open(os.path.join(os.path.dirname(os.path.abspath(dest_top)), '..', 'static', 'graph_explorer.html'), 'rt') as template:
|
||||
source = template.read()
|
||||
f.write(source.replace('<!-- REPLACE_THIS_WITH_GRAPH -->',
|
||||
json.dumps(graph)))
|
||||
logging.info("Generated {} files".format(files_generated))
|
||||
cur.close()
|
||||
db.commit()
|
||||
|
||||
@ -712,13 +712,17 @@ def render_connections(headline_id, content, graph):
|
||||
|
||||
# TODO: Cache results
|
||||
# TODO: Avoid querying graph API on script
|
||||
# TODO: Properly render outgouing links
|
||||
logging.info("Generating centered graph for {}".format(headline_id))
|
||||
import subprocess
|
||||
this_dir = os.path.dirname(os.path.abspath(__file__))
|
||||
os.makedirs('cache', exist_ok=True)
|
||||
subprocess.check_call(['python3', os.path.join(this_dir, 'gen-centered-graph.py'), headline_id, 'cache/' + headline_id + '.svg'])
|
||||
try:
|
||||
with open('cache/' + headline_id + '.svg') as f:
|
||||
content.append("<div class='connections'>{}</div>".format(f.read()))
|
||||
except FileNotFoundError:
|
||||
logging.exception('Graph file not produced on headline: "{}"'.format(headline_id))
|
||||
|
||||
def render(headline, doc, graph, headlineLevel):
|
||||
try:
|
||||
|
Loading…
Reference in New Issue
Block a user