{# title #}
{% if title is not defined or title is empty %}
  {%- set title_divider = page.metatags.title.divider|default(site.metatags.title.divider|default(' &middot; ')) %}
  {%- set title_only = page.metatags.title.only|default(site.metatags.title.only|default(false)) %}
  {%- set title_pagination_shownumber = page.metatags.title.pagination.shownumber|default(site.metatags.title.pagination.shownumber ?? true) %}
  {%- set title_pagination_label = page.metatags.title.pagination.label|default(site.metatags.title.pagination.label|default('Page %s')) %}
  {%- set title = page.title|e ~ title_divider ~ site.title|e %}
  {%- if title_only %}
    {%- set title = page.title|e %}
  {%- endif %}
  {%- if page.type == 'homepage' %}
    {%- set title = site.title|e ~ title_divider ~ site.baseline|default('')|e %}
    {%- if title_only or site.baseline|default('') is empty %}
      {%- set title = site.title|e %}
    {%- endif %}
  {%- endif %}
  {%- if page.paginator.current|default(0) > 1 %}
    {%- if title_pagination_shownumber %}
      {%- set title = page.title|e ~ title_divider ~ title_pagination_label|format(page.paginator.current) ~ title_divider ~ site.title|e %}
      {%- if title_only %}
        {%- set title = page.title|e ~ title_divider ~ title_pagination_label|format(page.paginator.current) %}
      {%- endif %}
    {%- endif %}
  {%- endif %}
{% endif %}
{# description #}
{% set description = page.description|default(site.description)|e %}
{# keywords / tags #}
{% set keywords = page.tags|default([])|merge(site.keywords|default([]))|e %}
{# author #}
{% set author = page.author|default(site.author|default(''))|e %}
{% if author is not empty %}
  {%- if author is not iterable %}
    {%- set author = {'name': author} %}
  {%- endif %}
  {%- if author.firstname is defined and author.lastname is defined %}
    {%- set author = author|merge({'name': author.firstname|e ~ ' ' ~ author.lastname|e}) %}
  {%- endif %}
{% endif %}
{# robots #}
{% set robots = page.metatags.robots|default(site.metatags.robots|default('index,follow')) %}
{% if page.paginator.current|default(0) > 1 %}
  {%- set robots = 'noindex,follow' %}
{% endif %}
{# favicon #}
{% if site.metatags.favicon.enabled ?? true %}
  {%- set favicon_defaults = {
    'icon': [32, 57, 76, 96, 128, 192, 228],
    'shortcut icon': [196],
    'apple-touch-icon': [120, 152, 180],
  } -%}
{% endif %}
{# image #}
{% if image is not defined or image is empty %}
  {%- set image = page.image|default(site.image|default()) %}
{% endif %}
{# open graph #}
{% set opengraph = {
  'locale': site.language.locale,
  'site_name': site.title,
  'type': 'website',
  'title': block('title'),
  'description': block('description'),
  'url': url(page, {canonical: true}),
} %}
{% if image %}
  {%- if image is not asset %}
    {%- set image_asset = asset(image) %}
  {%- else %}
    {%- set image_asset = image %}
  {%- endif %}
  {%- set opengraph = opengraph|merge({'image': image_asset|resize(1200)}) %}
{% endif %}
{% if page.section == site.metatags.articles|default('blog') %}
  {%- set opengraph = opengraph|merge({'type': 'article'}) %}
{% endif %}
{% if page.opengraph is defined or site.opengraph is defined %}
  {%- set opengraph = opengraph|merge(page.opengraph|default(site.opengraph)) %}
{% endif %}


    {#- template #}
    <title>{% block title %}{{ title }}{% endblock %}</title>
    <meta name="description" content="{% block description %}{{ description }}{% endblock %}" />
{%- if keywords ~%}
    <meta name="keywords" content="{{ keywords|join(', ') }}" />
{%- endif ~%}
{%- if author ~%}
    <meta name="author" content="{{ author.name|e }}" />
{%- endif ~%}
    <meta name="robots" content="{{ robots }}" />
{#- template: favicon ~#}
{%- if site.metatags.favicon.enabled ?? true and asset(site.metatags.favicon.image|default('favicon.png'), {'ignore_missing': true}) is not empty ~%}
  {%- for favicon_variant, favicon_sizes in site.metatags.favicon.sizes|default(favicon_defaults) -%}
    {%- for size in favicon_sizes ~%}
      {%- set favicon_asset = asset(site.metatags.favicon.image|default('favicon.png'), {'ignore_missing': true}) -%}
      {%- if not favicon_asset.missing ~%}
    <link rel="{{ favicon_variant }}" sizes="{{ size }}x{{ size }}" href="{{ favicon_asset|resize(size)|url({canonical: true}) }}" type="{{ favicon_asset.subtype }}" />
      {%- endif -%}
    {%- endfor -%}
  {%- endfor -%}
{%- endif ~%}
{#- template: alternates ~#}
{%- include 'partials/alternates.html.twig' with {'title': title, 'page': page} only ~%}
{#- template: alternates languages ~#}
{%- include 'partials/alternates-languages.html.twig' with {'page': page} only ~%}
{#- template: Open Graph ~#}
    <meta property="og:locale" content="{{ opengraph.locale }}" />
    <meta property="og:site_name" content="{{ opengraph.site_name }}" />
    <meta property="og:type" content="{{ opengraph.type }}" />
    <meta property="og:title" content="{{ opengraph.title }}" />
    <meta property="og:description" content="{{ opengraph.description }}" />
    <meta property="og:url" content="{{ url(page, {canonical: true}) }}" />
{%- if opengraph.image is defined ~%}
    <meta property="og:image" content="{{ opengraph.image|url({canonical: true}) }}" />
    <meta property="og:image:type" content="{{ opengraph.image.subtype }}" />
    <meta property="og:image:width" content="{{ opengraph.image.width }}" />
    <meta property="og:image:height" content="{{ opengraph.image.height }}" />
    <meta property="og:image:alt" content="{{ opengraph.title }}" />
{%- endif -%}