{% extends "base.html" %}

{% load i18n static dsfr_tags wagtailcore_tags wagtailimages_tags wagtail_dsfr_tags %}

{% block title %}
  <title>{{ page.seo_title|default:page.title }} — {{ settings.sites_conformes_content_manager.CmsDsfrConfig.site_title }}</title>
{% endblock title %}

{% if page.search_description %}
  {% block description %}
    <meta name="description" content="{{ page.search_description }}" />
  {% endblock description %}
{% endif %}

{% block social_media %}
  <meta property="og:site_name" content="{{ request.get_host }}" />
  <meta property="og:title"
        content="{% if page.seo_title %}{{ page.seo_title }}{% else %}{{ page.title }}{% endif %}" />
  <meta property="og:type" content="article" />
  <meta property="og:url" content="{% canonical_url %}" />
  <meta property="og:description" content="{{ page.search_description }}" />
  <meta property="og:locale" content="{{ LANGUAGE_CODE }}" />

  {% if page.get_translations.live %}
    {% for translation in page.get_translations.live %}
      <meta property="og:locale:alternate"
            content="{{ translation.locale.language_code }}" />
    {% endfor %}
  {% endif %}

  <meta name="twitter:title"
        content="{% if page.seo_title %}{{ page.seo_title }}{% else %}{{ page.title }}{% endif %}" />
  <meta name="twitter:description" content="{{ page.search_description }}" />
  {% include "blocks/socialmedia_preview_image.html" %}
{% endblock social_media %}

{% block content %}
  {% include "sites_conformes_content_manager/blocks/heading.html" %}

  {% with categories=page.blog_categories.all %}
    <div class="fr-container fr-mt-6w">
      <div class="fr-grid-row fr-grid-row--gutters">
        <div class="fr-col-12">
          {% include "sites_conformes_content_manager/blocks/breadcrumbs.html" %}
          {% if page.show_title %}
            <h1>
              {{ page.title }}
              {% include "sites_conformes_content_manager/blocks/page_visibility.html" %}
            </h1>
          {% endif %}
        </div>
      </div>
      <p>
        Publié le <a href="{% pageurl page.get_parent %}{% toggle_url_filter year=page.date.year %}">{{ page.date |date:'l j F Y' }}</a>
        {% if categories %}
          |
          {% for category in categories %}
            <a href="{% pageurl page.get_parent %}{% toggle_url_filter category=category %}">{{ category.name }}</a>
            {% if not forloop.last %},{% endif %}
          {% endfor %}
        {% endif %}
      </p>
    </div>

    {% include "sites_conformes_content_manager/blocks/messages.html" %}

    {% include "sites_conformes_content_manager/blocks/blocks_stream.html" with stream=page.body %}

    {% with authors=page.authors.all %}
      {% if authors %}
        <div class="fr-container fr-my-6w">
          <h2>{% translate "Posted by:" %}</h2>
          <div class="fr-grid-row fr-grid-row--gutters">
            {% for author in authors %}
              {% include "sites_conformes_blog/blocks/contact_card.html" with value=author %}
            {% endfor %}
          </div>
        </div>

      {% endif %}
    {% endwith %}

    {% if categories %}
      {% for category in categories %}
        {% include "sites_conformes_content_manager/blocks/blocks_stream.html" with stream=category.colophon %}
      {% endfor %}
    {% endif %}
  {% endwith %}

  <div class="fr-container fr-my-4w">
    {% for tag in page.tags.all|dictsort:"slug" %}
      <a class="fr-tag"
         target="_self"
         href="{% pageurl page.get_parent %}{% toggle_url_filter tag=tag %}">{{ tag }}</a>
    {% endfor %}
  </div>

  {% if settings.sites_conformes_content_manager.CmsDsfrConfig.show_share_links and settings.sites_conformes_content_manager.CmsDsfrConfig.share_links_blog_posts %}
    {% include "blocks/share.html" %}
  {% endif %}
{% endblock content %}
