{%- assign description = content | strip_html | split: " " | join: " " | escape | truncate: 150 -%}
{%- assign version = "1.0.2" -%}
{%- assign addons = "github, i18n, plugins, analytics" | split: ", " -%}

{%- include reset/site_pages.liquid %}
{%- include reset/i18n.liquid -%}
{%- include reset/schema.liquid -%}

{% comment %} github-metadata {% endcomment %}
{%- if jekyll.environment != "production" -%}
    {%- assign author = site.author | default: "[author]" -%}
    {%- assign branch = "[branch]" -%}
    {%- assign commit = "[commit]" -%}
    {%- assign repository_url = "#" -%}
    {%- assign issues_url = "#" -%}
    {%- assign zip_url = "#" -%}
    {%- assign github_edit_link = "#" -%}
{%- else -%}
    {%- assign author = site.author | default: site.github.owner_name -%}
    {%- assign branch = site.github.source.branch -%}
    {%- assign commit = site.github.build_revision | slice: 0, 7 -%}
    {%- assign repository_url = site.github.repository_url -%}
    {%- assign issues_url = site.github.issues_url -%}
    {%- assign zip_url = site.github.zip_url -%}
    {%- capture github_edit_link %}{% github_edit_link %}{% endcapture -%}
{%- endif -%}

{% comment %} scss and script {% endcomment %}
{%- capture site_scss -%}
    @import "site.scss";
    {%- if site.fluid %}
        @import "fluid.scss";
    {% endif -%}
    {% include assets/custom.scss %} {{ site.scss }}
{%- endcapture -%}

{%- capture site_script %}
    {% include assets/common.js %}
    {% include assets/custom.js %} {{ site.script }}
{%- endcapture -%}

{%- if site.debug -%}
    {%- assign cdn = site.baseurl -%}
{%- else -%}
    {%- assign cdn = "https://cdn.jsdelivr.net/gh/rundocs/jekyll-rtd-theme@" | append: version -%}
{%- endif -%}

{% comment %} title {% endcomment %}
{%- case page.url -%}
    {%- when "/" -%}
        {%- assign title = site.title | append: " · " | append: site.description -%}
    {%- when "/search.html" -%}
        {%- assign title = __search   | append: " · " | append: site.title -%}
    {%- when "/404.html" -%}
        {%- assign title = __404      | append: " · " | append: site.title -%}
    {%- else -%}
        {%- assign title = page.title | default: page.url | append: " · " | append: site.title -%}
{%- endcase -%}

{% comment %} content {% endcomment %}
{%- assign content = content
    | replace: '’', "'"
    | replace: '<pre class="highlight"><code>', "<pre>"
    | replace: '<pre><code class=', "<pre class="
    | replace: "</code></pre>", "</pre>"
    | replace: '<code class="language-plaintext highlighter-rouge">', '<code class="literal">'
    | replace: "<table>", '<table class="docutils align-default">' -%}

{% comment %} prev and next {% endcomment %}
{%- assign workdir_files = site_files | where_exp: "item", "item.dir == page.dir" -%}

{%- assign _index = 0 -%}
{%- for item in workdir_files %}
    {%- if item.url == page.url %}
        {%- assign _index = forloop.index -%}
    {%- endif %}
{%- endfor -%}

{%- for item in workdir_files -%}
    {%- assign _index_prev = _index | minus: 1 -%}
    {%- assign _index_next = _index | plus: 1 -%}
    {%- if forloop.index == _index_prev -%}
        {%- assign prev = item -%}
    {%- endif %}
    {%- if forloop.index == _index_next and page.url != page.dir -%}
        {%- assign next = item -%}
    {%- endif %}
{%- endfor -%}