{% set post = fn.get_post(fn.get_option('page_for_posts')) %}
{% set title = post.post_title %}
{% set content = post.post_content %}
{% set date = fn.get_the_date() %}

{% set thumbL = fn.get_the_post_thumbnail_url( post.ID, 'large') %}
{% set thumbM = fn.get_the_post_thumbnail_url(post.ID, 'medium') %}
{% set thumbS = fn.get_the_post_thumbnail_url(post.ID, 'thumbnail') %}
{% if not thumbL %}{% set thumbL = fn.get_template_directory_uri()~'/dist/images/og-format@3x.png' %}{% endif %}
{% if not thumbM %}{% set thumbM = fn.get_template_directory_uri()~'/dist/images/og-format@2x.png' %}{% endif %}
{% if not thumbS %}{% set thumbS = fn.get_template_directory_uri()~'/dist/images/og-format.png' %}{% endif %}

{# og #}
{% set og_title = title %}
{% set og_desc = post.post_excerpt %}
{% set og_thumb = fn.get_the_post_thumbnail_url(post.ID, 'thumbnail') %}
{% set og_url = fn.get_the_permalink(post.ID) %}
{% if not og_desc %}{% set og_desc =  post.post_excerpt ? post.post_excerpt : post.post_content|slice(0,180)  %}{% endif %}


{% extends 'm_layout/base.twig' %}

{% block main %}

<article class="m_panel" m-pack="single">
  <div class="grid--lg">
    {% include 'm_pages/components/headline.twig' with {
      title : title,
      text: content,
    }
    only %}
    {% if posts %}
    <div class="grid">
      {% for item in posts %}

        {% set related_title = item.post_title %}

        {% set related_content = item.post_excerpt
          ? item.post_excerpt
          : fn.wp_trim_words(item.post_content, 18, '...') %}

        {% set image = fn.get_post_thumbnail_id(item.ID)  %}

        <a href="{{fn.get_the_permalink(item.ID)}}" class="m_panel__block">
          <div class="m_panel__image">
            {% include 'm_components/widgets/picture.twig' with {image: image, title: title} only %}
            {% if item.post_type == "events" %}<time class="m_panel__date"><span class="day"> {{ item.start_date|date('d') }}</span>{{ item.start_date|date('M') }}</time>{% endif %}
          </div>
          <div class="m_panel__content">
            <h2 class="h4">{{ item.post_title }}</h2>
            {% if related_content %}
              <p>{{related_content|striptags}}</p>
            {% endif %}
            <span class="btn__arrow btn__arrow--right">Read more</span>
          </div>
        </a>

      {% endfor %}
    </div>
    {% endif %}
  </div>
</article>
  {% if comp %}
      {{ render_comp(comp, 'main') }}
  {% endif %}
{% endblock %}
