{% import "macros/authors.html" as authors_macros %}
{% import "macros/opengraph.html" as opengraph_macros %}

{% extends "base.html" %}

{% block stylesheet %}
<script src="{{ config.base_url }}/scripts/webmention.min.js" async></script>
<link rel="stylesheet" href="{{ config.base_url }}/blog.css">
{% endblock %}

{% block head_extra %}
{% if section %}
{{ opengraph_macros::opengraph(title=section.title, url=section.permalink, content=section.content, type="website") }}
{% else %}
{% if page.extra.image %}
{% set image = config.base_url ~ page.extra.image %}
{% else %}
{% set image = "" %}
{% endif %}
{{ opengraph_macros::opengraph(title=page.title, url=page.permalink, content=page.content, type="article", image=image) }}
{% endif %}
{% endblock %}

{% block content %}

{% if page %}
{% set newspaper_date = page.date %}
{% else %}
{% set newspaper_date = now() %}
{% endif %}
<header>
  <div id="title-date">
    <h1 class="newspaper-title"><a href="{{ config.base_url }}/blog/">The Ydreniv Time</a></h1>
    <time id="newspaper-time">{{ newspaper_date | date(format="%A, %B %-e %Y")}}</time>
  </div>
  <nav>
    {% include "includes/list-pages.html" %}
  </nav>
</header>

<div id="main">

  {% if section %}

  {{ section.content | safe }}

  <div class="h-feed">
    {% for page in paginator.pages %}
  <article class="h-entry">
    <header>
      <a class="u-url" href="{{ page.permalink }}"><h1 class="p-name">
          {{ page.title }}
      </h1></a>
      <p><strong class="subtitle"><time class="dt-published">{{ page.date | date }}</time></strong>, by {{ authors_macros::authors_inline(authors=page.extra.authors) }}</p>
      {% if page.updated != page.date -%}
      <p class="last-updated">This article has been edited on <time class="dt-updated">{{ page.updated | date }}</time>.</p>
      {% endif %}
    </header>
    <section class="e-content">
      {{ page.content | safe }}
    </section>
  </article>
    {% endfor %}
  </div>
    {% include "includes/pagination-navigation.html" %}

  {% elif page %}
  <article class="h-entry">
    <header>
      <h1 class="p-name">
        <a class="u-url" href="{{ page.permalink }}">{{ page.title }}</a>
      </h1>
      <p><strong class="subtitle"><time class="dt-published">{{ page.date | date }}</time></strong>, by {{ authors_macros::authors_inline(authors=page.extra.authors) }}</p>
      {% if page.updated != page.date -%}
      <p class="last-updated">This article has been edited on <time class="dt-updated">{{ page.updated | date }}</time>.</p>
      {% endif %}
    </header>
    <section class="e-content">
      {{ page.content | safe }}
    </section>
  </article>
  <div id="webmentions"></div>
  {% endif %}
</div>

{% include "includes/footer.html" %}

{% endblock content %}
