From 574936432ba61c4649a6d1c56d0c865533df2f0b Mon Sep 17 00:00:00 2001 From: "Prof. Dr. Matthias Jung DL9MJ" Date: Mon, 2 Jun 2025 21:20:03 +0200 Subject: [PATCH] refactor: simplify html page building --- src/build.py | 15 ++++++++++----- templates/html/html.html | 8 -------- templates/html/page.html | 21 ++++++++++++++------- 3 files changed, 24 insertions(+), 20 deletions(-) delete mode 100644 templates/html/html.html diff --git a/src/build.py b/src/build.py index 2d89383..65e05b0 100644 --- a/src/build.py +++ b/src/build.py @@ -89,9 +89,13 @@ class Build: ) # cached - def __build_page(self, content, course_wrapper=False) : + def __build_page(self, content, course_wrapper=False, sidebar=None) : page_template = self.env.get_template("page.html") - return page_template.render(content=content, course_wrapper=course_wrapper) + return page_template.render( + content=content, + course_wrapper=course_wrapper, + sidebar=sidebar + ) def __picture_handler(self, id): os.makedirs("build/pictures", exist_ok=True) @@ -220,11 +224,12 @@ class Build: def __build_html_page(self, contents, page): for content in contents: - template = self.env.get_template("html.html") if content["url_part"] == page: - result = template.render({"content": content}) with open(f"build/{page}.html", "w") as file: - result = self.__build_page(result) + result = self.__build_page( + content=content["content"], + sidebar=content["sidebar"] + ) file.write(result) def build_website(self): diff --git a/templates/html/html.html b/templates/html/html.html deleted file mode 100644 index c11e029..0000000 --- a/templates/html/html.html +++ /dev/null @@ -1,8 +0,0 @@ -{% if content["sidebar"] == None %} -{{ content["content"] }} -{% else %} -
-
{{ content["content"] }}
-
{{ content["sidebar"] }}
-
-{% endif %} \ No newline at end of file diff --git a/templates/html/page.html b/templates/html/page.html index bd72e97..4d3923d 100644 --- a/templates/html/page.html +++ b/templates/html/page.html @@ -103,13 +103,20 @@
{% endif %} - - {% if course_wrapper == True %} -
- {% endif %} - {{ content }} - {% if course_wrapper == True %} -
+ + {% if sidebar == None %} + {% if course_wrapper == True %} +
+ {{ content }} +
+ {% else %} + {{ content }} + {% endif %} + {% else %} +
+
{{ content }}
+
{{ sidebar }}
+
{% endif %}