summaryrefslogtreecommitdiffstatshomepage
path: root/templates/base.html
diff options
context:
space:
mode:
authorWolfgang Müller2021-06-16 12:05:24 +0200
committerWolfgang Müller2021-06-16 13:56:58 +0200
commit3946c3bfbdabc24cf57bcb1c0fa5a066dc23087e (patch)
treecf78e5f07b904f03b3ac11ff2f24e1f62ff72738 /templates/base.html
parentf6ad4f1472c2edc873c781e66e9bb057cfd204c0 (diff)
downloadzunzuncito-3946c3bfbdabc24cf57bcb1c0fa5a066dc23087e.tar.gz
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 № <X>". 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.
Diffstat (limited to 'templates/base.html')
-rw-r--r--templates/base.html32
1 files changed, 26 insertions, 6 deletions
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) -%}
+
<!DOCTYPE html>
<html lang="en">
<head>
- <title>{{ config.title ~ " · " }}{% block title %}{{ config.description }}{% endblock %}</title>
+ <title>
+ {{ config.title ~ " · " ~ title }}
+ </title>
<link rel="stylesheet" href="/style.css"/>
<link rel="icon" href="/icon.svg"/>
<link rel="alternate" type="application/atom+xml" title="zunzuncito" href="/atom.xml" />
- {%- block additional_feeds %}{% endblock %}
+ {% if term -%}
+ <link rel="alternate" type="application/atom+xml" title="zunzuncito - #{{ term.name }}" href="atom.xml" />
+ {% endif -%}
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
</head>
@@ -15,10 +33,12 @@
<header>
<h1><a href="/">{{ config.title }}</a></h1>
<div class="banner smaller">
- {{ config.description }} ·
- {%- block description %}
- <a href="/atom.xml">feed</a> · <a href="/tags">tags</a>
- {%- endblock %}
+ {{ config.description }}{% if description %} · {{ description }}{% endif %}
+ {% if section -%}
+ · <a href="/atom.xml">feed</a> · <a href="/tags">tags</a>
+ {% elif term -%}
+ · <a href="atom.xml">feed</a>
+ {% endif -%}
</div>
</header>
{%- block content %}{% endblock -%}