Redirect from subnote to parent note.

This commit is contained in:
Sergio Martínez Portela 2022-10-18 22:47:04 +02:00
parent a313597dcf
commit 7bad44cfb6

View File

@ -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"""<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>{title} @ {SITE_NAME}</title>
<meta http-equiv="refresh" content="0;./{topLevelHeadline.id}.node.html#{headline.id}" />
<link href="../static/style.css" rel="stylesheet"/>
</head>
<body>
<nav>
<h1><a href="/">Código para llevar [Notes]</a></h1>
</nav>
<a href='./{topLevelHeadline.id}.node.html#{headline.id}'>Sending you to the main note... [{org_rw.token_list_to_plaintext(topLevelHeadline.title.contents)}]</a>
</body>
</html>
"""
else:
return as_document(render(headline, doc, headlineLevel), title)
def render(headline, doc, headlineLevel):
try:
dom = headline.as_dom()