{% extends "layout.html" %}

{%- macro strip_meta(html, name) %}
{%- set text = html|
  replace('name="' + name + '"', '')|
  replace('content=', '')|
  replace('<meta', '')|
  replace('/>', '')|
  replace('"', '')|trim
-%}
{{ text }}
{%- endmacro %}

{%- macro og_meta() %}
{%- for html in metatags.split('\n') %}
  {%- if 'name="description"' in html %}
    {%- set text = strip_meta(html, 'description')|trim %}
    <meta property="og:description" content="{{ text }}">
  {%- elif 'name="image"' in html %}
    {%- set src = strip_meta(html, 'image')|trim %}
    <meta property="og:image" content="{{ src }}">
  {%- endif %}
{%- endfor %}
{%- endmacro %}

{% block extrahead %}
  <meta property="og:type" content="website">
  <meta property="og:site_name" content="{{ project }}">
  <meta property="og:title" content="{{ title|striptags|e }}">
  {%- if theme_description and 'name="description"' not in metatags %}
    <meta property="og:description" content="{{ theme_description }}">
  {%- else %}
    {{- og_meta() }}
  {%- endif %}
  {%- if theme_og_image and 'name="image"' not in metatags %}
    <meta property="og:image" content="{{ theme_og_image }}">
  {%- endif %}
  <meta name="twitter:card" content="summary">
  {%- if theme_twitter %}
  <meta name="twitter:creator" content="@{{ theme_twitter }}">
  {%- endif -%}
{% endblock %}

{% block body %}
  {{ body }}
  <div class="t-pagination clearfix">
    {%- if prev %}
    <span>
      ← <a href="{{ prev.link|e }}" title="{{ prev.title }}">{{ prev.title|truncate(30) }}</a>
    </span>
    {%- endif %}
    {%- if next %}
    <span style="float:right">
      <a href="{{ next.link|e }}" title="{{ next.title }}">{{ next.title|truncate(30) }}</a> →
    </span>
    {%- endif %}
  </div>
{% endblock %}
