{% extends "_base.html" %}

{% block seo -%}
  {{ super() }}

  {%- set og_title = page.title -%}

  {% if config.title and page.title -%}
  	{% set title = page.title ~ " | " ~ config.title -%}
  {% elif page.title -%}
		{% set title = page.title -%}
  {% elif config.title -%}
    {% set title = config.title -%}
  {% else -%}
    {% set title = "" -%}
  {% endif -%}

  {% if page.extra.author -%}
		{% set author = page.extra.author -%}
  {% endif -%}

  {% if page.description -%}
		{% set description = page.description -%}
  {% endif -%}

  {% if page.extra.image -%}
		{% set image = page.extra.image -%}
  {% endif -%}

  {% if page.extra.image_height -%}
		{% set image_height = page.extra.image_height -%}
  {% endif -%}

  {% if page.extra.image_width -%}
		{% set image_width = page.extra.image_width -%}
  {% endif -%}
  
  {{ macros::seo(title=title, og_title=og_title, author=author, description=description, site_url=site_url, image=image, image_height=image_height, image_width=image_width) }}
{%- endblock seo %}

{% block page %}post{% endblock page %}
{% block lang -%}
{%- set blog_section_path = config.extra.blog_section_path | trim_start_matches(pat="/") -%}
{%- set section_md_path = blog_section_path ~ "/_index.md" -%}
{%- set section = get_section(path=section_md_path, metadata_only=true) -%}
{%- if page.extra.lang %}{{page.extra.lang}}{% elif section.extra.lang %}{{section.extra.lang}}{% else %}{{page.lang}}{% endif -%}
{%- endblock lang %}
{% block title %}{{ page.title }}{% endblock title %}
{% block desc %}
  {% if page.summary %}
    {% set desc = page.summary %}
  {% elif page.description %}
    {% set desc = page.description %}
  {% endif %}
  {% if desc %}
  <meta name="description" content="{{ desc }}">
  {% endif %}
{% endblock desc %}

{% block head %}
{% if config.markdown.highlight_theme == "css" %}
<link id="hl" rel="stylesheet" type="text/css" href="/hl-light.css" />
{% endif %}
{% if page.extra.math %}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.7/dist/katex.min.css" integrity="sha384-3UiQGuEI4TTMaFmGIZumfRPtfKQ3trwQE2JgosJxCnGmQpL/lJdjpcHkaaFwHlcI" crossorigin="anonymous">
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.7/dist/katex.min.js" integrity="sha384-G0zcxDFp5LWZtDuRMnBkk3EphCK1lhEf4UEyEM693ka574TZGwo4IWwS6QLzM/2t" crossorigin="anonymous"></script>
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.7/dist/contrib/auto-render.min.js" integrity="sha384-+VBxd3r6XgURycqtZ117nYw44OOcIax56Z4dCRWbxyPt0Koah1uHoK0o4+/RRE05" crossorigin="anonymous"></script>
<script>
  document.addEventListener("DOMContentLoaded", function () {
    renderMathInElement(document.body, {
      delimiters: [
        { left: '$$', right: '$$', display: true },
        { left: '$', right: '$', display: false },
        { left: '\\(', right: '\\)', display: false },
        { left: '\\[', right: '\\]', display: true }
      ],
      throwOnError: false
    });
  });
</script>
{% endif %}
{% endblock head %}

{% block content %}
{% include "_header.html" %}
<div id="wrapper">
  <div id="blank"></div>
  <aside {% if config.extra.blur_effect %} class="blur" {% endif %}>
    {% if page.extra.toc is defined %}{% set show_toc = page.extra.toc %}{% else %}{% set show_toc = config.extra.toc %}{% endif %}
    {% if show_toc and page.toc %}
    <nav>
      <ul>
        {% for h2 in page.toc %}
        <li>
          <a class="h2" href="#{{ h2.id | safe }}">{{ h2.title }}</a>
          {% if h2.children %}
          <ul>
            {% for h3 in h2.children %}
            <li>
              <a class="h3" href="#{{ h3.id | safe }}">{{ h3.title }}</a>
            </li>
            {% endfor %}
          </ul>
          {% endif %}
        </li>
        {% endfor %}
      </ul>
    </nav>
    {% endif %}
    {% if config.extra.back_to_top %}
    <button id="back-to-top" aria-label="back to top">
      {% set icon = load_data(path="static/icon/arrow-up.svg") %}
      {{ icon | safe }}
    </button>
    {% endif %}
  </aside>
  <main>
    <div>
      {% if page.extra.copy is defined %}{% set allow_copy = page.extra.copy %}{% else %}{% set allow_copy = config.extra.copy %}{% endif %}
      {% if allow_copy %}
      {% set copy_icon = load_data(path="static/icon/copy.svg") %}
      {% set check_icon = load_data(path="static/icon/check.svg") %}
      <div id="copy-cfg" style="display: none;" data-copy-icon="{{ copy_icon }}" data-check-icon="{{ check_icon }}"></div>
      {% endif %}
      {% set backlink_icon = load_data(path="static/icon/backlink.svg") %}
      <article class="prose" data-backlink-icon="{{ backlink_icon }}">
        <h1>{{ page.title }}</h1>
        <div id="post-info">
          <div id="date">
            <span id="publish">{{ page.date | date }}</span>
            {% if page.updated and page.updated != page.date -%}
            <span>Updated: <span id="updated">{{ page.updated | date }}</span></span>
            {% endif -%}
          </div>

          {% if page.extra.display_tags is defined %}{% set display_tags = page.extra.display_tags %}{% elif config.extra.display_tags is defined %}{% set display_tags = config.extra.display_tags %}{% else %}{% set display_tags = true %}{% endif %}

          {% if page.taxonomies.tags is defined and display_tags == true %}
          <div id="tags">
            {% for tag in page.taxonomies.tags -%}
            {% set tag_slugify = tag | slugify -%}
            <a href="{{ config.base_url ~ '/tags/' ~ tag_slugify }}"><span>#</span>{{ tag }}</a>
            {%- endfor %}
          </div>
          {% endif %}
        </div>

        {% if page.extra.outdate_alert is defined %}{% set show_outdate_alert = page.extra.outdate_alert %}{% else %}{% set show_outdate_alert = config.extra.outdate_alert %}{% endif %}
        {% if page.extra.outdate_alert_days is defined %}{% set outdate_alert_days = page.extra.outdate_alert_days %}{% else %}{% set outdate_alert_days = config.extra.outdate_alert_days %}{% endif %}

        {% if show_outdate_alert -%}
        <blockquote id="outdate_alert" class="callout alert hidden" data-days="{{ outdate_alert_days }}"
          data-alert-text-before="{{ config.extra.outdate_alert_text_before }}"
          data-alert-text-after="{{ config.extra.outdate_alert_text_after }}">
          {% set icon = load_data(path="static/icon/alert.svg") %}
          <div class="icon">
            {{ icon | safe }}
          </div>
          <div class="content"></div>
        </blockquote>
        {% endif %}

        {% if page.extra.truncate_summary is defined %}{% set truncate_summary = page.extra.truncate_summary %}{% elif config.extra.truncate_summary is defined %}{% set truncate_summary = config.extra.truncate_summary %}{% else %}{% set truncate_summary = false %}{% endif %}

        {% if truncate_summary == true and page.summary %}
          {{ page.content | trim_start_matches(pat=page.summary) | safe }}
        {% else %}
          {{ page.content | safe }}
        {% endif %}
      </article>

      {% if page.extra.comment is defined %}{% set show_comment = page.extra.comment %}{% else %}{% set show_comment = config.extra.comment %}{% endif %}
      {% if show_comment %}
      <div class="giscus"></div>
      {% include "_giscus_script.html" %}
      {% endif %}
    </div>

    {% include "_footer.html" %}
  </main>
</div>
{% endblock content %}

{% block script %}
<script src="/js/lightense.min.js"></script>
{% endblock script %}