{% set page_slug = page.slug %}
{% extends "base.html" %}

{% block title %}
{% if page.breadcrumb %}
{% set breadcrumbs = page.breadcrumb.strip().split('\n') %}
{% for i in breadcrumbs %}{% set url, _, title = i.strip().partition(' ') %}{{ title|e }} &raquo; {% endfor %}
{% endif %}
{% if page.title == SITENAME|e %}
{{ page.title -}}
{% else %}
{{ page.title }} | {{ SITENAME|e -}}
{% endif %}
{% endblock %}

{% block head_links %}
  {% if page.css %}
  {% set styles = page.css.strip().split('\n') %}
  {% for style in styles %}
  <link rel="stylesheet" href="{{ style|expand_link(page)|e }}" />
  {% endfor %}
  {% endif %}
  {% if M_FAVICON %}
  <link rel="icon" href="{{ M_FAVICON[0]|format_siteurl|e }}" type="{{ M_FAVICON[1]|e }}" />
  {% endif %}
  <link rel="canonical" href="{{ page.url|format_siteurl|e }}" />
{% endblock %}

{% block meta %}
  {% if page.description %}
  <meta name="description" content="{{ page.description|dehyphenate|striptags|e }}" />
  {% endif %}
{% endblock %}

{% block social %}
  <meta property="og:site_name" content="{{ SITENAME|e }}" />
  <meta property="og:title" content="{{ page.title }}" />
  <meta name="twitter:title" content="{{ page.title }}" />
  <meta property="og:url" content="{{ page.url|format_siteurl|e }}" />
  {% if page.summary %}
  <meta property="og:description" content="{{ page.summary|dehyphenate|striptags|e }}" />
  <meta name="twitter:description" content="{{ page.summary|dehyphenate|striptags|e }}" />
  {% endif %}
  {% if page.cover %}
  <meta property="og:image" content="{{ page.cover|expand_link(page)|e }}" />
  <meta name="twitter:image" content="{{ page.cover|expand_link(page)|e }}" />
  <meta name="twitter:card" content="summary_large_image" />
  {% elif M_SOCIAL_IMAGE %}
  <meta property="og:image" content="{{ M_SOCIAL_IMAGE|format_siteurl }}" />
  <meta name="twitter:image" content="{{ M_SOCIAL_IMAGE|format_siteurl }}" />
  {% endif %}
  {% if not page.cover %}
  <meta name="twitter:card" content="summary" />
  {% endif %}
  <meta property="og:type" content="page" />
{% endblock %}

{% block extra %}
  {% if page.js %}
  {% set scripts = page.js.strip().split('\n') %}
  {% for script in scripts %}
  <script src="{{ script|expand_link(page)|e }}"></script>
  {% endfor %}
  {% endif %}
  {% if page.html_header %}
  {{ page.html_header|rtrim|indent(2) }}
  {% endif %}
{% endblock %}

{% block main %}
{% if not page.landing %}
{% if page.cover %}
<div id="m-cover-image" style="background-image: url('{{ page.cover|expand_link(page)|e }}');"><div></div></div>
{% endif %}
{% if page.header %}
<div class="m-container m-container-inflatable">
  <div class="m-row">
    <div class="m-col-l-10 m-push-l-1 m-nopadb">
<!-- header -->
{{ page.header|trim|expand_links(page) }}
<!-- /header -->
    </div>
  </div>
</div>
{% endif %}
{% endif %}
<article>
  {% if page.landing %}
  <div id="m-landing-image"{% if page.cover %} style="background-image: url('{{ page.cover|expand_link(page)|e }}');"{% endif %}>
    <div id="m-landing-cover">
      <div class="m-container">
<!-- landing -->
{{ page.landing|trim|expand_links(page) }}
<!-- /landing -->
      </div>
    </div>
  </div>
  {% endif %}
  <div class="m-container m-container-inflatable">
    <div class="m-row">
      <div class="m-col-l-10 m-push-l-1">
        {% if not page.landing %}
        {% if page.breadcrumb %}
        <h1>
          <span class="m-breadcrumb">
            {% set breadcrumbs = page.breadcrumb.strip().split('\n') %}
            {% for i in breadcrumbs %}
            {% set url, _, title = i.strip().partition(' ') %}
            <a href="{{ url|expand_link(page)|e }}">{{ title|e }}</a> &raquo;
            {% endfor %}
          </span>
          {{ page.title }}
        </h1>
        {% else %}
        <h1>{{ page.title }}</h1>
        {% endif %}
        {% endif %}
        {% if page.content %}
<!-- content -->
{% block page_content -%}
  {{- page.content|trim }}
{% endblock %}
<!-- /content -->
        {% endif %}
      </div>
    </div>
    {% if page.save_as == 'index.html' and not page.url and M_NEWS_ON_INDEX %}
    <div class="m-row">
      <div class="m-col-l-8 m-push-l-2">
        <div><div class="m-note m-default m-landing-news">
          <h3><a href="{{ M_BLOG_URL|format_siteurl|e }}">{{ M_NEWS_ON_INDEX[0]|e }} &raquo;</a></h3>
          <ul class="m-unstyled">
            {% for article in articles[0:M_NEWS_ON_INDEX[1]] %}
            <li><time class="m-text m-dim" datetime="{{ article.date.isoformat() }}">{{ article.locale_date }}</time><a href="{{ article.url }}">{{ article.title|e }}</a></li>
            {% endfor %}
          </ul>
        </div>
      </div></div>
    </div>
    {% endif %}
  </div>
</article>
{% if page.footer %}
<div class="m-container m-container-inflatable">
  <div class="m-row">
    <div class="m-col-l-10 m-push-l-1 m-nopadt">
<!-- footer -->
{{ page.footer|trim|expand_links(page) }}
<!-- /footer -->
    </div>
  </div>
</div>
{% endif %}
{% endblock %}
