{% macro post_metadata(post, indent_level=0, categories=True) -%}
{% filter indent(indent_level*4) %}
<div>
    <time datetime="{{ post.publish_date.strftime('%Y-%m-%d %H:%S') }}">{{ post.publish_date.strftime(site_info.display_date_format) }}</time>
	{% if categories %}
	{% if site_info.category_nav %}
	<a aria-label="link to category" href="{{ site_info.category_nav['categories'][post.front_matter.get('category', site_info.category_nav['uncategorized_name'])] | pyg_urlencode }}">{{ post.front_matter.get("category", site_info.category_nav["uncategorized_name"]) }}</a>
	{% elif post.front_matter.get("category") %}
	<span>{{ post.front_matter.get("category") }}</span>
	{% endif %}
	{% endif %}
</div>
{%- endfilter -%}
{%- endmacro -%}

{% extends "base.html" %}

{% block content %}
		{% if page.aggregated_posts %}
		{# list template #}
		{% if (page.pagination["root"] if page.pagination else page.href) != "/" %}
		<h2>{{ page.title }}</h2>
		{% endif %}
		<ol>
		{% for post in page.aggregated_posts %}
			<li><article>
				<header>
					{% if (page.pagination["root"] if page.pagination else page.href) != "/" %}
					<h3><a href="{{ post.href | pyg_urlencode }}">{{ post.title }}</a></h3>
					{% else %}
					<h2><a href="{{ post.href | pyg_urlencode }}">{{ post.title }}</a></h2>
					{% endif %}
					{{ post_metadata(post, 4) }}
				</header>
				<div class="article-excerpt">
					<p>{{ post.excerpt | indent(4) }}</p>
				</div>
			</article></li>
		{% endfor %}
		</ol>
		{% if page.pagination %}
		<nav class="pagination"><ul>
			{% set min_page = [1, page.pagination.page_number - 3] | max | int %}
			{% set max_page = [page.pagination.max_page_number, page.pagination.page_number + 3] | min | int %}
			{% if min_page != 1 %}
			<li><a aria-label="go to page 1" aria-current="{{ 'true' if page.pagination.page_number == 1 else 'false' }}" href="{{ page.pagination.first_page_href | pyg_urlencode }}">1</a></li>
			{% endif %}
			{% for i in range(min_page, max_page + 1) %}
			{% set root_href = page.pagination['root'].__str__() %}
			{% set root_href = root_href if root_href != "/" else "" %}
			<li><a aria-label="go to page {{ i }}" aria-current="{{ 'true' if page.pagination.page_number == i else 'false' }}" href="{% if i != 1 %}{{ root_href + ('/page%i' % i) | pyg_urlencode }}{% else %}{{ page.pagination.first_page_href | pyg_urlencode }}{% endif %}">{{ i }}</a></li>
			{% endfor %}
			{% if max_page != page.pagination.max_page_number %}
			<li><a aria-label="go to page {{ page.pagination.max_page_number }}" aria-current="{{ 'true' if page.pagination.page_number == page.pagination.max_page_number else 'false' }}" href="{{ page.pagination.last_page_href | pyg_urlencode }}">{{ page.pagination.max_page_number }}</a></li>
			{% endif %}
		</ul></nav>
		{% endif %}
	{% elif page.aggregated_grouped_posts %}
		{# archive and categories template #}
		<ol class="grouped-posts-list">
		{% for category, posts in page.aggregated_grouped_posts.items() %}
			<li><h2>{{ category }}</h2>
				<ol>
				{% for post in posts %}
					<li><article>
						<header>
							<h3><a href="{{ post.href | pyg_urlencode }}">{{ post.title }}</a></h3>
							{{ post_metadata(post, 7) }}
						</header>
					</article></li>
				{% endfor %}
				</ol>
			</li>
		{% endfor %}
		</ol>
	{% else %}
		{# single page/post template #}
		<article>
			<header>
				{% if page.href != "/" %}
				<h1>{{ page.title }}</h1>
				{% endif %}
				{% if page.is_post %}
				{{ post_metadata(page, 3) }}
				{% endif %}
			</header>
			<div class="article-content">
			{{ page.content | safe -}}
			</div>
		</article>
	{% endif %}
{% endblock %}
