{#
  Shared template (text-forge).

  Content repos may override by replacing their symlink/file in mkdocs/overrides,
  or by switching theme.custom_dir.

  Configuration is provided by text-forge plugin:
    - text-forge:
        source_file_published_title: "Опубликовано"
#}
<!--
  Copyright (c) 2016-2025 Martin Donath <martin.donath@squidfunk.com>

  Permission is hereby granted, free of charge, to any person obtaining a copy
  of this software and associated documentation files (the "Software"), to
  deal in the Software without restriction, including without limitation the
  rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  sell copies of the Software, and to permit persons to whom the Software is
  furnished to do so, subject to the following conditions:

  The above copyright notice and this permission notice shall be included in
  all copies or substantial portions of the Software.

  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  IN THE SOFTWARE.
-->

{# ---------------------------------------------------------------------- #}

<!-- Render date of creation -->
{% macro render_created(date) %}
<span class="md-source-file__fact">
  <span class="md-icon" title="{{ lang.t('source.file.date.created') }}">
    {% include ".icons/material/clock-plus-outline.svg" %}
  </span>{{ date }}</span>
{% endmacro %}

<!-- Render date of publication -->
{% macro render_published(date) %}
<span class="md-source-file__fact">
  <span class="md-icon" title="{{ text_forge_source_file_published_title }}">
    {% include ".icons/material/clock-check-outline.svg" %}
  </span>{{ date }}</span>
{% endmacro %}

<!-- Render date of last update -->
{% macro render_updated(date) %}
<span class="md-source-file__fact">
  <span class="md-icon" title="{{ lang.t('source.file.date.updated') }}">
    {% include ".icons/material/clock-edit-outline.svg" %}
  </span>{{ date }}</span>
{% endmacro %}

<!-- ---------------------------------------------------------------------- -->

<!-- Render authors -->
{% macro render_authors(authors) %}
  {% set git_authors = config.plugins["git-authors"] %}
  <span class="md-source-file__fact">
    <span class="md-icon" title="{{ lang.t('source.file.contributors') }}">
      {% if authors | length == 1 %}
        {% include ".icons/material/account.svg" %}
      {% else %}
        {% include ".icons/material/account-group.svg" %}
      {% endif %}
    </span>
    <nav>
      {% for author in authors %}
        {%- if git_authors.config.show_email_address %}
        <a href="mailto:{{ author.email }}">
          {{- author.name -}}
        </a>
        {%- else -%}
          {{- author.name -}}
        {% endif -%}
        {%- if loop.revindex > 1 %}, {% endif -%}
      {% endfor %}
    </nav>
  </span>
{% endmacro %}

<!-- ---------------------------------------------------------------------- -->

<!-- Render committers from GitHub -->
{% macro render_committers_github(title) %}
  <span class="md-icon" title="{{ lang.t('source.file.contributors') }}">
    {% include ".icons/material/github.svg" %}
  </span>
  <span>{{ title }}</span>
{% endmacro %}

<!-- Render committers from GitLab -->
{% macro render_committers_gitlab(title) %}
  <span class="md-icon" title="{{ lang.t('source.file.contributors') }}">
    {% include ".icons/material/gitlab.svg" %}
  </span>
  <span>{{ title }}</span>
{% endmacro %}

<!-- Render committers -->
{% macro render_committers(authors) %}
  <span class="md-source-file__fact">
    {% if committers_source == "gitlab" %}
      {{ render_committers_gitlab("GitLab") }}
    {% else %}
      {{ render_committers_github("GitHub") }}
    {% endif %}
    <nav>
      {% for author in authors[:4] %}
        <a
          href="{{ author.url }}"
          class="md-author"
          title="@{{ author.login }}"
        >
          {% set separator = "&" if "?" in author.avatar else "?" %}
          <img
            src="{{ author.avatar }}{{ separator }}size=72"
            alt="{{ author.name or 'GitHub user' }}"
          />
        </a>
      {% endfor %}

      <!-- More authors -->
      {% set more = authors[4:] | length %}
      {% if more > 0 %}
        {% if page.edit_url %}
          <a
            href="{{ page.edit_url | replace('edit', 'blob') }}"
            class="md-author md-author--more"
          >
            +{{ more }}
          </a>
        {% else %}
          <span class="md-author md-author--more">
            +{{ more }}
          </span>
        {% endif %}
      {% endif %}
    </nav>
  </span>
{% endmacro %}


<!-- ---------------------------------------------------------------------- -->

<!-- Determine date of creation -->
{% if page.meta %}
  {% if page.meta.created %}
    {% set created = page.meta.created %}
  {% elif page.meta.git_creation_date_localized %}
    {% set created = page.meta.git_creation_date_localized %}
  {% endif %}

  <!-- Determine date of publication -->
  {% if page.meta.published %}
    {% set published = page.meta.published %}
  {% endif %}

  <!-- Determine date of last update -->
  {% if page.meta.git_revision_date_localized %}
    {% set updated = page.meta.git_revision_date_localized %}
  {% elif page.meta.updated or page.meta.revision_date %}
    {% set updated = page.meta.updated or page.meta.revision_date %}
  {% endif %}
{% endif %}

<!-- Source file information -->
{% if updated or published or created or git_info or committers %}
  <aside class="md-source-file">

    <!-- Date of creation -->
    {% if created %}
      {{ render_created(created) }}
    {% endif %}

    <!-- Date of publication -->
    {% if published %}
      {{ render_published(published) }}
    {% endif %}

    <!-- Date of last update -->
    {% if updated %}
      {{ render_updated(updated) }}
    {% endif %}

    <!-- Authors (git-authors plugin) -->
    {% if git_info %}
      {{ render_authors(git_info["page_authors"]) }}
    {% endif %}

    <!-- Authors (git-committers plugin) -->
    {% if committers %}
      {{ render_committers(committers) }}
    {% endif %}
  </aside>
{% endif %}
