From 7bad44cfb6334c576df0381337eeb56095a56298 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20Mart=C3=ADnez=20Portela?= Date: Tue, 18 Oct 2022 22:47:04 +0200 Subject: [PATCH] Redirect from subnote to parent note. --- scripts/generate.py | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/scripts/generate.py b/scripts/generate.py index fa7a12f..62d39de 100644 --- a/scripts/generate.py +++ b/scripts/generate.py @@ -139,8 +139,8 @@ def regen_all(src_top, dest_top, *, docs=None, db=None): with open(endpath, "wt") as f: doc_to_headline_remapping['id:' + doc.id] = 'id:' + main_headline.id - f.write(as_document(render(main_headline, doc, headlineLevel=0), - org_rw.token_list_to_plaintext(main_headline.title.contents))) + f.write(render_as_document(main_headline, doc, headlineLevel=0, + title=org_rw.token_list_to_plaintext(main_headline.title.contents))) files_generated += 1 elif doc.id is not None: logging.error("Cannot render document from id: {}. {} headlines {} related".format( @@ -201,15 +201,15 @@ def regen_all(src_top, dest_top, *, docs=None, db=None): # Render HTML with open(endpath, "wt") as f: - f.write(as_document(render(headline, doc, headlineLevel=0), - org_rw.token_list_to_plaintext(headline.title.contents))) + f.write(render_as_document(headline, doc, headlineLevel=0, + title=org_rw.token_list_to_plaintext(headline.title.contents))) files_generated += 1 if headline.id == INDEX_ID: index_endpath = os.path.join(dest_top, "index.html") with open(index_endpath, "wt") as f: - f.write(as_document(render(headline, doc, headlineLevel=0), - org_rw.token_list_to_plaintext(headline.title.contents))) + f.write(render_as_document(headline, doc, headlineLevel=0, + title=org_rw.token_list_to_plaintext(headline.title.contents))) files_generated += 1 # Update graph, replace document ids with headline ids @@ -418,6 +418,30 @@ def render_inline(tree, f): return ''.join(acc) +def render_as_document(headline, doc, headlineLevel, title): + if isinstance(headline.parent, org_rw.Headline): + topLevelHeadline = headline.parent + while isinstance(topLevelHeadline.parent, org_rw.Headline): + topLevelHeadline = topLevelHeadline.parent + return f""" + + + + {title} @ {SITE_NAME} + + + + + + Sending you to the main note... [{org_rw.token_list_to_plaintext(topLevelHeadline.title.contents)}] + + + """ + else: + return as_document(render(headline, doc, headlineLevel), title) + def render(headline, doc, headlineLevel): try: dom = headline.as_dom()