{% import "macros/macros.html" as post_macros %}

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    {% if page.extra.meta %}
        <!-- the meta data config goes here  -->
        {% for data in page.extra.meta %}
            <meta
                {% for key, value in data%}
                    {% if key == "property" and value == "og:title"%}
                        {% set_global page_has_og_title = true -%}
                    {% endif %}
                    {% if key == "property" and value == "og:description"%}
                        {% set_global page_has_og_description = true -%}
                    {% endif %}
                    {% if key == "name" and value == "description"%}
                        {% set_global page_has_description = true -%}
                    {% endif %}
                    {{ key }}="{{ value }}"
                {% endfor %}
            />
        {% endfor %}
    {% endif %}

    {% if current_path == "/" %}
        <title>
            {{ config.title | default(value="Home") }}
        </title>
        {% if not page_has_og_title %}
            <meta property="og:title" content="{{ config.title | default(value="Home") }}" />
        {% endif %}
    {% else %}
        <title>
            {% if page.title %} {{ page.title }}
            {% elif config.title %} {{ config.title }}
            {% else %} Post {% endif %}
        </title>

        {% if not page_has_og_title %}
            <meta property="og:title" content="{% if page.title -%}{{ page.title }}{% elif config.title -%}{{ config.title }}{% else -%}Post{% endif -%}" />
        {% endif %}
    {% endif %}

    {% if not page_has_og_description %}
        {% if page.description %}
            <meta property="og:description" content="{{ page.description }}" />
        {% elif config.description %}
            <meta property="og:description" content="{{ config.description }}" />
        {% endif %}
    {% endif %}

    {% if not page_has_description %}
        {% if page.description %}
            <meta name="description" content="{{ page.description }}" />
        {% elif config.description %}
            <meta name="description" content="{{ config.description }}" />
        {% endif %}
    {% endif %}

    {% if config.extra.favicon %}
         <link rel="icon" type="image/png" href={{ config.extra.favicon }} />
    {% endif %}

    {# opengraph, twitter_cards #}

    {% if config.extra.ga %}
        <!-- Global site tag (gtag.js) - Google Analytics -->
        <script async src="https://www.googletagmanager.com/gtag/js?id={{config.extra.ga}}"></script>
        <script>
            window.dataLayer = window.dataLayer || [];
            function gtag(){dataLayer.push(arguments);}
            gtag('js', new Date());

            gtag('config', '{{config.extra.ga}}');
        </script>
    {% endif %}

    {# if need icon, load feather.js #}
    {% if config.extra.social and config.extra.useCDN | default(value=false) %}
        <script src="https://cdn.jsdelivr.net/npm/feather-icons/dist/feather.min.js"></script>
    {% elif config.extra.social or config.extra.mode == "toggle" %}
        <script src={{ get_url(path="js/feather.min.js") }}></script>
    {% endif %}


    {% if config.extra.useCDN | default(value=false) %}
        <link href="https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:ital,wght@1,500&display=swap" rel="stylesheet">
        <link href="https://fonts.googleapis.com/css2?family=Fira+Sans&display=swap" rel="stylesheet">
        <link href="https://fonts.googleapis.com/css?family=Roboto+Mono" rel="stylesheet">
    {% else %}
        <link href={{ get_url(path="css/fonts.css") }} rel="stylesheet" />
    {% endif %}

    <link rel="stylesheet" type="text/css" media="screen" href={{ get_url(path="css/main.css") }} />

    {% if config.extra.mode == "auto" or config.extra.mode == "dark" or config.extra.mode == "toggle" %}
        <link
            rel="stylesheet"
            id="darkModeStyle"
            type="text/css"
            href={{ get_url(path="css/dark.css") }}
            {% if config.extra.mode == "auto" %}
                media="(prefers-color-scheme: dark)"
            {% endif %}
            {% if config.extra.mode == "toggle" %}
                disabled
            {% endif %}
        />
    {% endif %}

    {% if config.extra.katex_enable %}
        <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.9/dist/katex.min.css" integrity="sha384-n8MVd4RsNIU0tAv4ct0nTaAbDJwPJzDEaqSD1odI+WdtXRGWt2kTvGFasHpSy3SV" crossorigin="anonymous">
        <script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.9/dist/katex.min.js" integrity="sha384-XjKyOOlGwcjNTAIQHIpgOno0Hl1YQqzUOEleOLALmuqehneUG+vnGctmUb0ZY0l8" crossorigin="anonymous"></script>
        <script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.9/dist/contrib/auto-render.min.js" integrity="sha384-+VBxd3r6XgURycqtZ117nYw44OOcIax56Z4dCRWbxyPt0Koah1uHoK0o4+/RRE05" crossorigin="anonymous"
    onload="renderMathInElement(document.body);"></script>
    {% endif %}


    {# TODO: custom css and js. #}


</head>
