{% macro post_link(page) %}
    <div>
        {% set translations = page.translations | filter(attribute="lang", value=lang) %}
        {% if translations %}
            {% set post = get_page(path = translations.0.path) %}
        {% else %}
            {% set post = page %}
            {% set not_translated = true %}
        {% endif %}
        <h2 class="post-title"><a href="/{{ post.path | safe }}">{{ post.title }}</a></h2>
        <div class="post-summary">
            {{ post.summary | safe}}
            <a class="read-more" href="/{{ post.path | safe }}">read&nbsp;more…</a>

            {% if not_translated %}
            <aside class="no-translation">
                (This post is not translated yet.)
            </aside>
            {% endif %}
        </div>
    </div>
{% endmacro post_link %}

{% macro utterances() %}
    <script src="https://utteranc.es/client.js"
        repo="phil-opp/blog_os"
        issue-term="url"
        label="comments"
        crossorigin="anonymous"
        async>
    </script>
{% endmacro utterances %}

{% macro toc(toc) %}
    <details id = "toc-inline">
        <summary><b>Table of Contents</b></summary>
        <ul>
            {% for h2 in toc %}<li>
                <a href="#{{h2.id | safe}}">{{ h2.title | safe }}</a>
                {% if h2.children %}<ul>
                    {% for h3 in h2.children %}<li>
                        <a href="#{{h3.id | safe}}">{{ h3.title | safe }}</a>
                    </li>{% endfor %}
                </ul>{% endif %}
            </li>{% endfor %}
        </ul>
    </details>
{% endmacro toc %}
