{% import "macros/feed.html" as feed_macros %}

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    
    <title>
    {%- block title -%}
        {% if page.title %}{{ page.title }}
        {% elif section.title %}{{ section.title }}
        {% elif config.title %}{{ config.title }}
        {% endif %}
    {%- endblock -%}
    </title>

    {%- if config.generate_feeds %}
            {%- for feed in config.feed_filenames -%}
                {{ feed_macros::link_alternate(filename=feed, title=config.title) }}
            {% endfor -%}
        {%- block feeds -%}{%- endblock -%}
    {% endif %}

    <link rel="stylesheet" href="{{ get_url(path='style.css', cachebust=true) }}">
    <link rel="stylesheet" href="{{ get_url(path='giallo.css') }}">
    
    {%- if page.extra.stylesheets or section.extra.stylesheets %}
        {%- for stylesheet in page.extra.stylesheets | default(value=section.extra.stylesheets) %}
            <link rel="stylesheet" href="{{ get_url(path=stylesheet, cachebust=true) }}">
        {% endfor -%}
    {%- endif %}
    
    {%- if config.extra.favicon %}
        {% set image_meta = get_image_metadata(path=config.extra.favicon) -%}
        <link rel="icon" type="{{ image_meta.mime | safe }}" href="{{ get_url(path=config.extra.favicon) }}">
        {%- if image_meta.mime is ending_with("png") %}
            {% set resized_image = resize_image(path=config.extra.favicon, width=180, height=180, op="fit") -%}
            <link rel="apple-touch-icon" href="{{ resized_image.url | safe }}">
        {%- endif -%}
    {%- elif config.extra.favicon_emoji %}
        <link rel="icon" href="data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'><text y='.9em' font-size='90'>{{ config.extra.favicon_emoji }}</text></svg>">
    {%- endif %}

    {% if current_url %}
        <meta property="og:url" content="{{ current_url | safe }}">
        <link rel="canonical" href="{{ current_url | safe }}">
    {% endif %}

    {% if page -%}
        <meta property="og:type" content="article">
    {% else -%}
        <meta property="og:type" content="website">
    {% endif -%}
    
    {% if page.title %}
        <meta property="og:title" content="{{ page.title }}">
        <meta property="twitter:title" content="{{ page.title }}">
    {% endif %}
    <meta property="twitter:card" content="summary_large_image">

    {% if page.extra.preview_img %}
        <meta property="og:image"       content="{{ get_url(path=page.extra.preview_img) }}" >
        <meta property="twitter:image"       content="{{ get_url(path=page.extra.preview_img) }}" >
    {% endif %}



    {%- if page.authors -%}
        {%- for author in page.authors %}
            <meta name="author" content="{{ author }}">
        {%- endfor -%}
    {%- elif page and config.author %}
        <meta name="author" content="{{ config.author }}">
    {%- endif %}

    {%- block description -%}
        {%- if config.description %}
            <meta name="description" content="{{ config.description }}">
        {%- endif %}
    {%- endblock %}

    <meta name="color-scheme" content="dark">


    {%- if page.description -%}
        <meta property="og:description" content="{{ page.description | markdown(inline=true) | striptags }}">
    {% elif page.summary -%}
        {%- set inline_summary = page.summary | linebreaksbr | replace(from="<br>", to=" ") | striptags -%}
        <meta property="og:description" content="{{ inline_summary | trim_end_matches(pat=".") | safe }}…">
    {%- elif section.description -%}
        <meta property="og:description" content="{{ section.description | markdown(inline=true) | striptags }}">
    {% elif config.description -%}
        <meta property="og:description" content="{{ config.description }}">
    {% endif -%}
    
    <meta property="og:site_name" content="{{ config.title }}">
    <meta property="og:updated_time" content="{{ now() }}">
    
    {%- if page.date %}
        <meta property="article:published_time" content="{{ page.date | date(format="%+") }}">
    {%- endif -%}
    
    {%- if page.updated %}
        <meta property="article:modified_time" content="{{ page.updated | date(format="%+") }}">
    {%- endif -%}
    
    {%- if page.taxonomies and page.taxonomies.categories %}
        <meta property="article:section" content="{{ page.taxonomies.categories[0] }}">
    {%- endif -%}
    
    {%- if page.taxonomies and page.taxonomies.tags -%}
        {%- for tag in page.taxonomies.tags %}
            <meta property="article:tag" content="{{ tag }}">
        {%- endfor -%}
    {%- endif -%}
</head>


<body data-theme="dark">
    <div class="content">
        <header class="header">
            {% filter indent -%}{%- filter indent -%}
            {%- block header -%}
            {% include "partials/header.html" %}
            {%- endblock -%}
            {%- endfilter -%}{%- endfilter %}
        </header>
        <main id="main">
            {% block main %}{% endblock %}
        </main>
        <footer class="footer">
            {% filter indent -%}{%- filter indent -%}
            {%- block footer -%}
            {% include "partials/footer.html" %}
            {%- endblock -%}
            {%- endfilter -%}{%- endfilter %}
        </footer>
    </div>

    <div id="lightbox" class="lightbox" aria-hidden="true" role="dialog" aria-label="Image viewer">
    <div class="lightbox__stage">
        <img id="lightbox-img" class="lightbox__img" alt="">
    </div>
    </div>
</body>
<script src="{{ get_url(path='/js/script.js') }}"></script>
</html>