{% extends "layout.html" %}

{% block title %}Bibliography{% endblock %}

{% block breadcrumb %}
  <li><a href="/bibliography">Bibliography</a>
{% endblock %}

{% macro letters() %}
  {% set letter = [""] %}{# Jinja needs a ridiculous hack for global variables #}

  <ul id="letters">
  {% for entry in entries if entry.author %}{# FDL wreaks havoc in the Stacks project bibliography so we filter on non-zero entry.author#}
    {% if not entry.author[0] | lower == letter[-1] %}
      {% do letter.append(entry.author[0] | lower) %}

      <li><a href="#letter-{{ letter[-1] }}">{{ letter[-1] | upper }}</a>
    {% endif %}
  {% endfor %}
  </ul>
{% endmacro %}

{% block hamburger %}
  {{ letters() }}
{% endblock %}

{% block body %}
  {% set letter = [""] %}{# Jinja needs a ridiculous hack for global variables #}

  {% for entry in entries if entry.author %}{# FDL wreaks havoc in the Stacks project bibliography so we filter on non-zero entry.author#}
    {% if not entry.author[0] | lower == letter[-1] %}
      {% do letter.append(entry.author[0] | lower) %}

      {% if not loop.first %}</ul>{% endif %}
      <a id="letter-{{ letter[-1] }}" class="header-offset"></a>
      <h2>{{ letter[-1] | upper }}</h2>
      <ul class="entries">
    {% endif %}

    <li>{{ entry.author | safe }}, <a href="/bibliography/{{ entry.key }}">{{ entry.title | safe }}</a>
    {% if loop.last %}</ul>{% endif %}
  {% endfor %}
  </ul>
{% endblock %}

{% block sidebar %}
  {{ letters() }}
{% endblock %}
