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()