summaryrefslogtreecommitdiff
path: root/templates/macros/blog.html
diff options
context:
space:
mode:
authorDennis Fink2026-06-18 17:57:51 +0200
committerDennis Fink2026-06-18 17:57:51 +0200
commita4e35942fee745e64db5d0099ba2582e0fb4417e (patch)
treef109c3e77805cdacd6f443c8a2d47514be5254a2 /templates/macros/blog.html
parente0904e48a5c1c5b327c29218fb39bf2fa05f1871 (diff)
downloaddennisfink.me-a4e35942fee745e64db5d0099ba2582e0fb4417e.tar.gz
dennisfink.me-a4e35942fee745e64db5d0099ba2582e0fb4417e.zip
Build the first usable version of the blog
This adds the Lektor project structure, models, templates, styling, feeds, categories, tags, archives, custom Markdown heading handling, and the initial content needed to make the blog usable.
Diffstat (limited to 'templates/macros/blog.html')
-rw-r--r--templates/macros/blog.html100
1 files changed, 100 insertions, 0 deletions
diff --git a/templates/macros/blog.html b/templates/macros/blog.html
new file mode 100644
index 0000000..b4caafe
--- /dev/null
+++ b/templates/macros/blog.html
@@ -0,0 +1,100 @@
+{% from "macros/pagination.html" import render_pagination %}
+
+{% macro render_toc(toc, maxdepth=2) %}
+ <nav aria-label="Table of contents">
+ <p>Table of contents</p>
+ <ol>
+ {% for item in toc recursive %}
+ <li>
+ <a href="#{{ item.anchor }}">{{ item.title }}</a>
+ {% if item.children and loop.depth < maxdepth %}
+ <ol>
+ {{ loop(item.children) }}
+ </ol>
+ {% endif %}
+ </li>
+ {% endfor %}
+ </ol>
+ </nav>
+{% endmacro %}
+
+{% macro render_blog_post(post, show_toc=True) %}
+ <article>
+ <header>
+ <div>
+ <h2>
+ <a href="{{ post|url }}">{{ post.title }}</a>
+ </h2>
+ <dl>
+ {% if post.publication_date %}
+ <div>
+ <dt>Posted:</dt>
+ <dd>
+ <a href="{{ ('/blog@index-pages/year/{}'.format(post.publication_date.year) ) | url }}">
+ <time datetime="{{ post.publication_date | dateformat('yyyy-MM-dd') }}">{{ post.publication_date | dateformat("d MMMM yyyy") }}</time>
+ </a>
+ </dd>
+ </div>
+ {% else %}
+ <div class="missing-publication-date-warning" role="alert">
+ <dt>⚠</dt>
+ <dd>
+ Missing publication date
+ </dd>
+ </div>
+ {% endif %}
+ {% if post.updated_date and post.publication_date and (post.updated_date > post.publication_date) %}
+ <div>
+ <dt>Last updated:</dt>
+ <dd>
+ <time datetime="{{ post.updated_date | dateformat('yyyy-MM-dd') }}">{{ post.updated_date | dateformat("d MMMM yyyy") }}</time>
+ </dd>
+ </div>
+ {% endif %}
+ {% if post.category %}
+ <div>
+ <dt>Category:</dt>
+ <dd>
+ {% set category = site.get('/categories/'+post.category) %}
+ <a href="{{ category|url }}">{{ category.name }}</a>
+ </dd>
+ </div>
+ {% endif %}
+ </dl>
+ </div>
+ {% if show_toc and post.render_toc %}
+ {% set toc = post.body.toc|default([]) %}
+ {{ render_toc(toc) }}
+ {% endif %}
+ </header>
+ {{ post.body }}
+ {% if post.tags %}
+ <footer>
+ <p>Tagged with</p>
+ <ul aria-label="Tags">
+ {% for tag in post.tags %}
+ <li>
+ {% set tag_slug = tag|trim|lower|replace(" ", "-") %}
+ <a href="{{ ('/blog/tag/' ~ tag_slug ~ '/')|url }}" rel="tag">{{ tag }}</a>
+ {%- if not loop.last -%}, {%- else -%}.{%- endif -%}
+ </li>
+ {% endfor %}
+ </ul>
+ </footer>
+ {% endif %}
+ </article>
+{% endmacro %}
+
+{% macro render_blog_index(pagination) %}
+ {% for post in pagination.items %}
+ {{ render_blog_post(post, False) }}
+ {% if not loop.last %}
+ <hr>
+ {% endif %}
+ {% endfor %}
+ {% if pagination.pages > 1 %}
+ <footer>
+ {{ render_pagination(pagination) }}
+ </footer>
+ {% endif %}
+{% endmacro %}