summaryrefslogtreecommitdiff
path: root/templates/macros/blog.html
blob: 904e59eafd8b72a064c2511f1e936a6ff74799f4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
{% 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 class="h-entry">
    <header>
      <div>
        <h2>
          <a href="{{ post|url }}" class="u-url p-name">{{ 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') }}"
                        class="dt-published">{{ 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') }}"
                      class="dt-updated">{{ 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 }}" class="p-category">{{ category.name }}</a>
              </dd>
            </div>
          {% endif %}
          <a rel="author"
             class="p-author h-card display-none"
             href="{{ '/about' | url(absolute=True) }}">Dennis Fink</a>
        </dl>
      </div>
      {% if show_toc and post.render_toc %}
        {% set toc = post.body.toc|default([]) %}
        {{ render_toc(toc) }}
      {% endif %}
    </header>
    <div class="e-content">{{ post.body }}</div>
    {% 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"
                 class="p-category">{{ 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 %}