From e97316c9b721f6386e58831321ec699a8e091d31 Mon Sep 17 00:00:00 2001 From: Zachary Vance Date: Wed, 3 Jul 2024 15:17:10 -0400 Subject: [PATCH] Add general template to avoid duplicating layout stuff --- blog | 11 ++- config.yaml | 4 +- templates/category.mustache.html | 7 ++ templates/layout.mustache.html | 116 +++++++++++++++++++++++ templates/post.mustache.html | 123 +----------------------- templates/tag.mustache.html | 155 ++----------------------------- 6 files changed, 146 insertions(+), 270 deletions(-) create mode 100644 templates/category.mustache.html create mode 100644 templates/layout.mustache.html diff --git a/blog b/blog index fb90e70..d3839bc 100755 --- a/blog +++ b/blog @@ -83,6 +83,7 @@ setTimeout(function() { """ class Templatable(PseudoMap): + use_layout = True def __init__(self, blog): self.blog = blog @@ -103,7 +104,13 @@ class Templatable(PseudoMap): return mustache.render(template, context, warn=True) def content(self): - return self.render_template(self.blog, self.type, self.context).encode("utf8") + content = self.render_template(self.blog, self.type, self.context) + if self.use_layout: + return self.render_template(self.blog, "layout", collections.ChainMap({ + "content": content, + }, self, self.blog)).encode("utf8") + else: + return def output(self): output = self.content() @@ -118,6 +125,7 @@ class Templatable(PseudoMap): return collections.ChainMap(self, self.blog) class Static(Templatable): + use_layout = False def __init__(self, path, blog): super().__init__(blog) self.path = path @@ -171,6 +179,7 @@ class Page(Templatable): pass # TODO class Image(Templatable): + use_layout = False pass # TODO class Blog(PseudoMap): diff --git a/config.yaml b/config.yaml index b040a37..806e4ae 100644 --- a/config.yaml +++ b/config.yaml @@ -2,6 +2,7 @@ source: "/home/zachary/blog" destination: "/home/zachary/blog/public" web_root: "https://blog2.za3k.com" +title: 'blog of zachary "za3k" vance' post_dir: "posts" page_dir: "pages" @@ -11,10 +12,11 @@ tag_template: "templates/tag.mustache.html" category_template: "templates/tag.mustache.html" post_template: "templates/post.mustache.html" tagcloud_template: "templates/tagcloud.mustache.html" +layout_template: "templates/layout.mustache.html" post_destination: "{{destination}}/posts/{{id}}.html" tag_destination: "{{destination}}/tag/{{slug}}.html" -category_destination: "{{destination}}/category/{{category}}.html" +category_destination: "{{destination}}/category/{{slug}}.html" page_destination: "{{destination}}/{{page}}" image_destination: "{{destination}}/images/{{image}}" static_destination: "{{destination}}/{{relative_path}}" diff --git a/templates/category.mustache.html b/templates/category.mustache.html new file mode 100644 index 0000000..830c2cf --- /dev/null +++ b/templates/category.mustache.html @@ -0,0 +1,7 @@ + + +{{# posts }} + {{& post }} +{{/ posts }} diff --git a/templates/layout.mustache.html b/templates/layout.mustache.html new file mode 100644 index 0000000..e988917 --- /dev/null +++ b/templates/layout.mustache.html @@ -0,0 +1,116 @@ + + + {{ title }} + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+
+
+
+
+ {{& content }} +
+ +
+
+
+
+ +
+ + + + + diff --git a/templates/post.mustache.html b/templates/post.mustache.html index 04260d0..63084aa 100644 --- a/templates/post.mustache.html +++ b/templates/post.mustache.html @@ -1,119 +1,4 @@ - - - {{ title }} - - - - - - - - - - - - - - - - - - - -
-
- - - -
-
-
-
-
- {{& post }} -
- {{& comments }} -
-
- -
-
-
-
- -
- - - - - +{{& post }} +
+ {{& comments }} +
diff --git a/templates/tag.mustache.html b/templates/tag.mustache.html index 833776e..056b87c 100644 --- a/templates/tag.mustache.html +++ b/templates/tag.mustache.html @@ -1,150 +1,7 @@ + - - - - - - - -{{ tag }} - - - - - - - - - - - - - - - - - -
- -
- - - -
-
- -
- - -
- -
- - - - - {{# posts }} - {{& post }} - {{/ posts }} - - -
- - -
- -
- -
-
-
- - +{{# posts }} + {{& post }} +{{/ posts }} -- 2.47.3