{# Some common data #}
{%if page.path or section.path %}
    {% set title = page.title | default(value=section.title) %}
    {% set path = page.path | default(value=section.path) %}
    {% set content = page.content | default(value=section.content) %}
    {% set extra = page.extra | default(value=section.extra) %}
    {% set is_blog_post = path != "/blog/" and path is starting_with("/blog/") %}
{% else %}
{# If here, we are on the 404 page #}
{% set title = "NOT FOUND" %}
{% set path = "/404" %}
{% set extra = [] %}
{% set is_blog_post = false %}
{% endif %}

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

<head>
    {% block head %}
        <!--noformat-->
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>{{title}} | {{config.title}}</title>
        <link rel="shortcut icon" type="image/jpg" href="{{config.extra.profile_photo | safe}}" />

        {% if current_url %}<link rel="canonical" href="{{current_url | safe}}" />{% endif %}

        <link rel="alternate" type="application/rss+xml" title="RSS"
            href="{{get_url(path=config.feed_filename, trailing_slash=false) | safe}}">

        {# OpenGraph #}
        <meta name="twitter:card" content="summary" />
        <meta name="og:site" content="{{config.extra.domain_name}}" />
        <meta name="og:site_name" content="{{config.title}}" />
        {% set opengraph_image = extra.og_image | default(value=config.extra.profile_photo)%}
        <meta name="og:image" content="{{opengraph_image | safe}}" />
        {% if extra.og_description %}
            <meta property="og:description" content="{{extra.og_description}}" />
            <meta property="description" content="{{extra.og_description}}" />
            <meta name="description" content="{{extra.og_description}}">
        {% elif page.description %}
            <meta property="og:description" content="{{page.description}}" />
            <meta property="description" content="{{page.description}}" />
            <meta name="description" content="{{page.description}}">
        {% endif %}
        <meta property="og:title" content="{{title}} - {{config.title}}" />
        {% if page.path %}<meta property="og:type" content="{{extra.og_type | default(value='article')}}" />{% endif %}
        {% if page.date %}<meta property="article:published_time" content="{{page.date}}" />{% endif %}

        {# Fonts #}
        <link rel="preconnect" href="https://fonts.googleapis.com">
        <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
        <link href="https://fonts.googleapis.com/css2?family=Open+Sans&display=swap" rel="stylesheet">

        {# Allow pages to import custom CSS if they need #}
        {% for url in extra.css_import | default(value=[]) %}
        <link rel="stylesheet" href="{{url}}"> <!-- Requested by Page -->
        {% endfor %}

        {# Allow pages to import custom Head JS if they need #}
        {% for url in extra.head_js_import | default(value=[]) %}
        <script src="{{url}}"></script> <!-- Requested by Page -->
        {% endfor %}

        <link rel="stylesheet" href="/styles.css">
        <!--noformat-->
    {% endblock head %}
</head>

<body>

    {# Heading section (profile photo & name) #}
    <header data-size="{% if path == '/' %}large{% else %}small{% endif %}">
        <img src="{{config.extra.profile_photo}}" alt="Evan Pratten">
        <div class="header-text">
            <span class="header-name">Evan Pratten</span><br>
            <span class="header-tagline">Software Developer</span>
            <hr>
            <ul class="header-links">
                <li>
                    <a target="_blank" href="mailto:{{config.extra.email}}" rel="me">
                        <img src="/dist/line-awesome/envelope.svg" alt="email: " loading="lazy">
                        <span>{{config.extra.email}}</span>
                    </a>
                </li>
                <li>
                    <a target="_blank" href="https://github.com/{{config.extra.github}}" rel="me">
                        <img src="/dist/line-awesome/github.svg" alt="github: " loading="lazy">
                        <span>{{config.extra.github}}</span>
                    </a>
                </li>
                <li>
                    <a target="_blank" href="https://linkedin.com/in/{{config.extra.linkedin}}" rel="me">
                        <img src="/dist/line-awesome/linkedin.svg" alt="linkedin: " loading="lazy">
                        <span>{{config.extra.linkedin}}</span>
                    </a>
                </li>
            </ul>
        </div>
    </header>

    {# Navigation #}
    <nav>
        <hr>
        <ul>
            <li><a href="/">Home</a></li>
            <li><a href="/blog">Blog</a></li>
            <li><a href="/radio">Radio</a></li>
            <li><a href="/music">Music</a></li>
            <li><a href="/photography">Photos</a></li>
            <li><a href="/contact">Contact</a></li>
        </ul>
        <hr>
    </nav>

    {# Announcement Handling #}
    {% if config.extra.home_announcement and path == "/" %}
    <div class="announcement">
        <span>{{config.extra.home_announcement | safe}}</span>
    </div>
    {% elif config.extra.global_announcement %}
    <div class="announcement">
        <span>{{config.extra.global_announcement | safe}}</span>
    </div>
    {% endif %}

    {# Page Content #}
    <main>
        {% block content %}
        <article>
            {% if not extra.no_auto_title %}
            <h1 class="title">{{title}}</h1>
            {% endif %}
            {% if page.description %}
            <em class="subtitle">{{page.description}}</em><br>
            {% endif %}
            <br>

            {{ content | safe }}
        </article>
        {% endblock content %}
    </main>

    {# Footer #}
    <footer>
        {% if is_blog_post %}
        <br>
        <p id="sponsor-notice">Consider <a href="https://ewp.fyi/sponsor">sponsoring my work</a>!</p>
        {% endif %}
        <br>
        <hr>
        <p id="copyright">
            Copyright &copy; 2017 - {{ now() | date(format="%Y") }}
            <strong>Evan Warren Pratten</strong>
        </p>
    </footer>

    <div>
        {# Goatcounter #}
        <script data-goatcounter="https://analytics.ewpratten.com/count" async src="//gc.zgo.at/count.js"></script>

        {# Google Analytics #}
        <script defer src="https://www.googletagmanager.com/gtag/js?id=G-5912H4H03P"></script>
        <script>
            window.dataLayer = window.dataLayer || [];
            function gtag() { dataLayer.push(arguments); }
            gtag('js', new Date());

            gtag('config', 'G-5912H4H03P');
        </script>

        {# Mermaid #}
        <script src="https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.min.js" defer></script>
        <script>mermaid.initialize({ startOnLoad: true });</script>

        {# MathJax #}
        <script src='https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/latest.js?config=TeX-MML-AM_CHTML' async
            defer></script>
        <script type="text/x-mathjax-config">
            MathJax.Hub.Config({tex2jax: {inlineMath: [['$','$'], ['\\(','\\)']], displayMath: [ ['$$','$$'], ['\[','\]'] ]}});
        </script>
    </div>

    {# Allow pages to import custom CSS if they need #}
    <div>
        {% for url in extra.js_import | default(value=[]) %}
        <script async src="{{url}}" defer></script> <!-- Requested by Page -->
        {% endfor %}
    </div>

    {# Used to for brid.gy verification #}
    <a href="https://ewpratten.com" class="h-card" rel="me" hidden>Evan Pratten</a>
</body>

</html>