From 3946c3bfbdabc24cf57bcb1c0fa5a066dc23087e Mon Sep 17 00:00:00 2001 From: Wolfgang Müller Date: Wed, 16 Jun 2021 12:05:24 +0200 Subject: templates: Consolidate blocks into base template This is the first in a series of commits that will attempt to clean up and simplify the templates, most of which were put together hastily. One particular egregious example of this is how Tera blocks are employed to set per-page titles, provide banner descriptions and links, and include additional RSS feeds. These elements are all outside the normal 'content' block provided by the base template. Almost always they contain only one line of text. This solution was chosen because there did not seem to be a cleaner way of having per-page variables in the base template. This is a problem especially for the 'single' and list' taxonomy pages which do not even have front matter (and therefore cannot carry additional metadata). Furthermore, we want to keep each page's front matter as minimal as possible and avoid hard-coding a post description of "post № ". Instead rely on the fact that each type of page is identifiable in the base template by the variables that are set in it. The index carries the 'section' variable, pages carry 'page', a single taxonomy term carries 'term', and a single taxonomy carries 'terms'. Using this information we can consolidate all these blocks into the base template in a simple and clean way. --- templates/base.html | 32 ++++++++++++++++++++++++++------ templates/page.html | 12 ------------ templates/tags/list.html | 8 -------- templates/tags/single.html | 12 ------------ 4 files changed, 26 insertions(+), 38 deletions(-) (limited to 'templates') diff --git a/templates/base.html b/templates/base.html index edce080..8c42d17 100644 --- a/templates/base.html +++ b/templates/base.html @@ -1,12 +1,30 @@ {% import "macros.html" as macros -%} + +{%- if page -%} + {%- set description = "post № " ~ page.slug -%} + {%- set title = page.title | default(value=description) -%} +{%- elif term -%} + {%- set description = "posts tagged with #" ~ term.name -%} + {%- set title = description -%} +{%- elif terms -%} + {%- set description = "all tags" -%} + {%- set title = description -%} +{%- endif -%} + +{%- set title = title | default(value=config.description) -%} + - {{ config.title ~ " · " }}{% block title %}{{ config.description }}{% endblock %} + + {{ config.title ~ " · " ~ title }} + - {%- block additional_feeds %}{% endblock %} + {% if term -%} + + {% endif -%} @@ -15,10 +33,12 @@

{{ config.title }}

{%- block content %}{% endblock -%} diff --git a/templates/page.html b/templates/page.html index 394dd97..07fe19d 100644 --- a/templates/page.html +++ b/templates/page.html @@ -1,17 +1,5 @@ {% extends "base.html" -%} -{%- block title -%} -{%- if page.title -%} -{{ page.title }} -{%- else -%} -post № {{ page.slug }} -{%- endif -%} -{%- endblock title -%} - -{%- block description %} -post № {{ page.slug }} -{%- endblock description %} - {%- block content %} {{ macros::render_post(post=page, in_feed=false) }} {%- if "mentions" in page.extra and page.extra.mentions | length > 0 -%} diff --git a/templates/tags/list.html b/templates/tags/list.html index 0cab254..260bb57 100644 --- a/templates/tags/list.html +++ b/templates/tags/list.html @@ -1,13 +1,5 @@ {% extends "base.html" %} -{%- block title -%} -all tags -{%- endblock title -%} - -{%- block description %} -all tags -{%- endblock description %} - {% block content %}