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

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta http-equiv="content-type" content="text/html; charset=utf-8">

        <meta name="viewport" content="width=device-width, initial-scale=1">
        <meta name="HandheldFriendly" content="True">
        <link rel="icon" type="image/png" href="/favicon.png" />

        <meta name="application-name" content="{{ config.title }}" />
        <meta name="author" content="{{ config.extra.author }}" />

        {% if page.title -%}
            <meta name="title" content="{{ page.title }}" />
            <meta name="og:title" content="{{ page.title }}" />
        {%- elif section.title -%}
            <meta name="title" content="{{ section.title }}" />
            <meta name="og:title" content="{{ section.title }}" />
        {%- else -%}
            <meta name="title" content="{{ config.title }}" />
            <meta name="og:title" content="{{ config.title }}" />
        {%- endif %}

        {% if page.description -%}
            <meta name="description" content="{{ page.description }}" />
            <meta name="og:description" content="{{ page.description }}" />
        {%- elif section.description -%}
            <meta name="description" content="{{ section.description }}" />
            <meta name="og:description" content="{{ section.description }}" />
        {%- else -%}
            <meta name="description" content="{{ config.description }}" />
            <meta name="og:description" content="{{ config.description }}" />
        {%- endif %}

        {% if page.permalink -%}
            <meta name="og:permalink" content="{{ page.permalink }}" />
        {%- elif section.permalink -%}
            <meta name="og:permalink" content="{{ section.permalink }}" />
        {%- endif %}

        {% set keywords = [] -%}
        {%- if page.taxonomies.tags -%}
            {% set_global keywords = page.taxonomies.tags %}
        {%- endif -%}
        {%- if keywords | length == 0 -%}
            {%- set tags = get_taxonomy(kind="tags") -%}
            {%- if tags.items | length > 0 -%}
                {%- for tag in tags.items -%}
                    {%- set_global keywords = keywords | concat(with=tag.name) -%}
                {%- endfor -%}
            {%- endif -%}
        {%- endif -%}
        {%- if keywords | length > 0 -%}
            <meta name="keywords" content="{{ keywords | join(sep=",") }}"/>
        {%- endif %}

        <title>
            {%- block title -%}
                {%- if page.title -%}
                    {{ page.title }}{{ " · " }}
                {%- endif -%}
                {%- if section.title -%}
                    {{ section.title }}{{ " · " }}
                {%- endif -%}
                {{ config.title }}
            {%- endblock title -%}
        </title>

        {% block css -%}
            <link id="style-dark" rel="stylesheet" href="{{ get_url(path="site_dark.css", trailing_slash=false) | safe }}?i={{ config.extra.random }}">
            <link id="style-light" disabled rel="stylesheet" href="{{ get_url(path="site_light.css", trailing_slash=false) | safe }}?i={{ config.extra.random }}">

            {%- if page.extra.zenn_applause -%}
                <link rel="stylesheet" href="{{ get_url(path="vendor/applause-button/applause-button.css", trailing_slash=false) | safe }}?i={{ config.extra.random }}">
            {%- endif -%}
        {%- endblock css %}

        {% block js -%}
            <script src="{{ get_url(path="js/theme.js", trailing_slash=false) | safe }}?i={{ config.extra.random }}"></script>

            {%- if page.extra.zenn_applause -%}
                <script src="{{ get_url(path="vendor/applause-button/applause-button.js", trailing_slash=false) | safe }}?i={{ config.extra.random }}"></script>
            {%- endif -%}
        {%- endblock js %}

        {% if config.generate_feed -%}
            <link rel="alternate" type="application/rss+xml" title="RSS" href="{{ get_url(path="rss.xml") | safe }}">
        {%- endif %}

        {%- block extra_head %}
        {% endblock extra_head %}
    </head>

    <body class="notransition">
        {% if config.extra.zenn_title -%}
            {% block header %}
                <header id="banner">
                    <a href="/" class="logo">{{ config.extra.zenn_title }}</a>

                    {% if config.extra.zenn_menu -%}
                        <section id="navbar" class="navbar">
                            <ul>
                                <nav itemscope itemtype="http://schema.org/SiteNavigationElement">
                                    {% for item in config.extra.zenn_menu %}
                                        <li>
                                            <a itemprop="url"
                                                    class="{% if item.url | replace(from="$BASE_URL", to=config.base_url) == current_url %}active{% endif %}"
                                                    href="{{ item.url | safe | replace(from="$BASE_URL", to=config.base_url) }}">
                                                <span itemprop="name">{{ item.name }}</span>
                                            </a>
                                        </li>
                                    {% endfor %}
                                </nav>
                            </ul>
                        </section>
                    {%- endif %}

                    <section class="actions">
                        <a href="#" class="theme-toggle" onclick="theme_toggle(); return false;" title="Toggle light/dark mode">
                            {{ load_data(path="static/icons/glyphicons-halflings-51-contrast.svg") | safe -}}
                        </a>
                        <a href="#" class="navbar-toggle" onclick="navbar_toggle(); return false;" title="Show/hide navbar">
                            {{ load_data(path="static/icons/glyphicons-halflings-227-menu.svg") | safe -}}
                        </a>
                    </section>
                </header>
            {% endblock header %}
        {%- endif -%}

        {% block headertron %}{% endblock headertron %}

        {% block main %}
            <main>
                <content>
                    {% if section.title -%}
                        <header>
                            <h1>
                                {{ section.title }}
                                {%- if paginator -%}
                                    {% if paginator.current_index > 1 %}
                                        &nbsp;&middot;&nbsp; Page {{ paginator.current_index }}
                                    {% endif %}
                                {%- endif -%}
                                {%- include "anchor-link.html" -%}
                            </h1>

                            {%- if not section.extra.zenn_hide_header_meta -%}
                                {%- block header_meta -%}{%- endblock header_meta -%}
                            {%- endif %}
                        </header>
                    {%- endif %}
                    {% if page.title -%}
                        <header>
                            <h1>
                                {{ page.title }}
                                {%- include "anchor-link.html" -%}
                            </h1>

                            {%- if not page.extra.zenn_hide_header_meta -%}
                                {%- block header_meta -%}{%- endblock header_meta -%}
                            {%- endif %}
                        </header>
                    {%- endif %}

                    {% block body -%}{%- endblock body %}

                    {% block page_footer %}{% endblock page_footer %}
                </content>
            </main>

            <footer class="muted">
                Copyright &copy; {{ config.title }} 2021-{{ now() | date(format="%Y") }}.

                <ul>
                    <li><a href="/tags" title="Browse tags">Tags</a></li>
                    <li><a href="/categories" title="Browse categories">Categories</a></li>
                    {% if config.extra.zenn_source %}
                        <li><a href="{{ config.extra.zenn_source }}" target="_blank">Source</a></li>
                    {% endif %}
                </ul>
            </footer>

        {% endblock main %}
    </body>

</html>
