1
0
em.0x45.cz/templates/macros.html

59 lines
1.8 KiB
HTML

{% macro list_posts(section=false, count=0, taxonomy=false) %}
{% if taxonomy == false and section != false %}
{% set section = get_section(path=section~"/_index.md") %}
{% endif %}
{% for page in section.pages %}
{% if loop.index > count and count != 0 %}
{% break %}
{% endif %}
{{ self::print_article(page=page) }}
{% endfor %}
{% endmacro %}
{% macro print_article(page) %}
<article>
<h2><a href="{{ page.permalink }}">{{ page.title }}</a></h2>
<p>{{ page.summary | safe }}</p>
{{ self::page_info(page=page) }}
</article>
{% endmacro %}
{% macro page_info(page) %}
{% if page.date %}
<div class="info">
<span class="date">{{ page.date }}</span>
{%- if page.extra.author -%}
, <span class="author">{{ page.extra.author }}</span>
{% endif %}
{% if page.taxonomies.categories %}
<div class="taxonomy">
{{ self::list_taxonomy(kind="categories", page=page.taxonomies.categories, prepend="#") }}
</div>
{% endif %}
</div>
{% endif %}
{% endmacro %}
{% macro list_taxonomy(kind, page=false, prepend="") %}
{#
Option `kind` must always be set and specifies the wanted taxonomy.
If `page` is set, this macro only prints items specific for this page.
Otherwise it prints all items. It expects `page.taxonomies.<taxonomy>`.
Option `prepend` can be used to prepend any string to the item name.
#}
<ul>
{% if page != false %}
{% for term in page %}
<li class="item"><a href="{{ get_taxonomy_url(kind=kind, name=term) | safe }}">{{ prepend }}{{ term }}</a></li>
{% endfor %}
{% else %}
{% set taxonomy = get_taxonomy(kind=kind) %}
{% for term in taxonomy.items %}
<li class="item"><a href="{{ term.permalink | safe }}">{{ prepend }}{{ term.name }}</a></li>
{% endfor %}
{% endif %}
</ul>
{% endmacro %}