summaryrefslogtreecommitdiffstats
path: root/templates/macros.html
blob: a2376caf41819efe62e93ca7476ac9b463b39b3d (plain)
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
{# vim: set ft=htmldjango: #}
{% macro nav_item(name, url) %}
  {% if page %}
    {% set curr_url = get_url(path=page.path) %}
  {% elif section %}
    {% set curr_url = get_url(path=section.path) %}
  {% endif %}
  {% set url = url | trim_end_matches(pat="/") %}
  <a {% if curr_url == url %}class="active"{% endif %} href={{ url }}>{{ name }}</a>
{% endmacro nav %}
{% macro toc_item(item, depth=0) %}
  <li>
    <a href="{{ item.permalink | safe }}">{{ item.title }}</a>
    {% if depth < 6 and item.children %}
      <ul>
        {% for child in item.children %}{{ self::toc_item(item=child, depth=depth + 1) }}{% endfor %}
      </ul>
    {% endif %}
  </li>
{% endmacro %}
{% macro toc(toc) %}
  {%- set len = toc | length -%}
  {% if len > 1 %}
    <nav>
      <ul>
        {% for child in page.toc %}{{ self::toc_item(item=child) }}{% endfor %}
      </ul>
    </nav>
  {% endif %}
{% endmacro %}
{% if page.summary %}
  <p>{{ page.summary | safe }}</p>
  <a href="{{ page.permalink }}#continue-reading">...</a>
{% endif %}
{% macro post_header(page_ref=false) %}
  {% set page = page_ref | default(value=page) %}
  <header>
    <hgroup>
      <h1>
        {%- if page_ref -%}
          <a href="{{ page.permalink }}">{{ page.title | safe }}</a>
        {% else %}
          {{ page.title | safe }}
        {%- endif -%}
      </h1>
      <p>{{ page.description | default(value="") | markdown(inline=true) | safe }}</p>
    </hgroup>
    <footer>
      Posted on
      <time pubdate datetime="{{ page.date | date(format="%Y-%m-%d") }}">{{ page.date | date(format="%d %b %Y") }}</time>
      by
      <address class="author"> <a rel="author" href="{{ config.base_url }}">{{ config.extra.author }}</a></address>
    </footer>
  </header>
  {% if page_ref and page.summary %}
    <p>{{ page.summary | safe }}</p>
    <a href="{{ page.permalink }}#continue-reading">...</a>
  {% else %}
    {{ self::toc(toc=page.toc) }}
  {% endif %}
{% endmacro %}