diff options
Diffstat (limited to 'templates/macros/blog.html')
| -rw-r--r-- | templates/macros/blog.html | 100 |
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 %} |
