From 8698035f2e422d2b9554cf3f4ef280899fe3b792 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20Mart=C3=ADnez=20Portela?= Date: Sat, 7 May 2022 20:38:12 +0200 Subject: [PATCH] Collapse non top-level nodes. --- _scripts/generate.py | 34 +++++++++++++++++++++++++++------- static/style.css | 12 ++++++++++++ 2 files changed, 39 insertions(+), 7 deletions(-) diff --git a/_scripts/generate.py b/_scripts/generate.py index 3ecad4c..8bde3a5 100644 --- a/_scripts/generate.py +++ b/_scripts/generate.py @@ -17,6 +17,7 @@ EXTENSIONS = [ ".org.txt", ] +MIN_HIDDEN_HEADLINE_LEVEL = 2 def load_all(top_dir_relative): top = os.path.abspath(top_dir_relative) @@ -92,7 +93,7 @@ def main(src_top, dest_top): main_headline = [h for h in topHeadlines if h != related][0] with open(endpath, "wt") as f: - f.write(as_document(render(main_headline, doc))) + f.write(as_document(render(main_headline, doc, headlineLevel=0))) files_generated += 1 else: logging.error("Cannot render document from id: {}. {} headlines {} related".format( @@ -105,7 +106,7 @@ def main(src_top, dest_top): endpath = os.path.join(dest_top, headline.id + ".node.html") with open(endpath, "wt") as f: - f.write(as_document(render(headline, doc))) + f.write(as_document(render(headline, doc, headlineLevel=0))) files_generated += 1 logging.info("Generated {} files".format(files_generated)) @@ -200,7 +201,7 @@ def render(headline, doc): content = [] render_tree(dom, content) for child in headline.children: - content.append(render(child, doc)) + content.append(render(child, doc, headlineLevel=headlineLevel+1)) if headline.state is None: state = "" @@ -211,16 +212,22 @@ def render(headline, doc): todo_state = "todo" else: todo_state = "done" + + display_state = 'collapsed' + if headlineLevel < MIN_HIDDEN_HEADLINE_LEVEL: + display_state = 'expanded' + return f""" -
+

{state} - + {html.escape(headline.title)}

- - {''.join(content)} +
+ {''.join(content)} +
""" @@ -230,6 +237,19 @@ def as_document(html): + {html} diff --git a/static/style.css b/static/style.css index b112b50..3ca95d9 100644 --- a/static/style.css +++ b/static/style.css @@ -12,6 +12,18 @@ border-left: 2px solid #2c3e50; } +.node.collapsed > .contents { + display: none; +} + +.node .node.collapsed > .title::before { + content: "🮥"; +} + +.node .node.expanded > .title::before { + content: "🮦"; +} + h1 { font-size: 150%; }