aboutsummaryrefslogtreecommitdiff
path: root/templates/macros/macros.html
blob: 541ebfebef8354487f052488f9eda3b31efe5cf3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
{%- macro title(page) %}
        <h1><a href="{{ page.permalink | safe }}">{{ page.title }}</a></h1>
        <span>{{ page.date | date(format="%B %d, %Y") }}
        {%- if page.taxonomies.authors and config.taxonomies %} by
          {%- for author in page.taxonomies.authors %}
          {%- if author_flag %} and {% endif %}
          <a href="{{ get_taxonomy_url(kind='authors', name=author) | safe }}">{{ author }}</a>
          {%- set_global author_flag = true %}
          {%- endfor %}
        {%- elif config.extra.author and config.extra.author_show %} by {{ config.extra.author }}
        {%- endif %}
{%- if page.taxonomies.categories %} [{% for cat in page.taxonomies.categories %}<a href="{{ get_taxonomy_url(kind="categories", name=cat) | safe }}">{{ cat }}</a>{% endfor %}]{% endif %}
{%- if page.taxonomies.tags %} {%- for tag in page.taxonomies.tags %} #<a href="{{ get_taxonomy_url(kind="tags", name=tag) | safe }}">{{ tag }}</a> {% endfor -%}{%- endif %}
{%- if config.extra.readtime %} - {{ page.reading_time }} {{ config.extra.readtime_string | default(value="min") }} {% endif %}
        </span>
{%- endmacro title %}


{%- macro footer(page) %}
<p><b><a href="#">Back to top</a></b></p>
{%- endmacro footer %}


{%- macro pagination(paginator)%}
  {%- if paginator.number_pagers > 1 %}
            {%- if paginator.number_pagers <= 5 %}  {# 5 or less pager is simple, just display all 5 #}
                {%- set start = 1 %}
                {%- set end = paginator.number_pagers %}
            {%- endif %}

            {%- if paginator.number_pagers > 5 %}

                {%- if paginator.current_index >= 3 %}                {# Check if the first number will be 1 or not #}
                    {%- set start = paginator.current_index - 2 %}    {# Set the start number #}
                    {%- if paginator.number_pagers - paginator.current_index < 2 %}  {# the last two pages your no longer centered with equal pages start and end #}
                        {%- set difference = paginator.number_pagers - paginator.current_index %}
                        {%- set compensation =  1 - difference %}
                        {%- set start = paginator.current_index - 3 - compensation %}  {# however many pages are missing on the end, add offset to start #}
                    {%- endif %}
                {%- else %}
                    {%- set start = 1 %}
                {%- endif %}

                {%- if paginator.number_pagers >= paginator.current_index + 2 %}  {# Check if the last page is beyond our range #}
                    {%- set end = paginator.current_index + 2 %}  {# End is beyond our range so we can safely set it to our range #}
                    {%- if paginator.current_index <= 3 %}  {# check offset start, if on page 1 or 2 then set the end to page 5 #}
                        {%- set end = 5 %}
                    {%- endif %}
                {%- else %}
                    {%- set end = paginator.number_pagers %}
                {%- endif %}
            {%- endif %}
      <nav>
          <ul>
            {%- if paginator.previous %}<li><a href="{{ paginator.first | safe }}">&#124; &#60;</a></li>{% else %}<li><span class="off">&#124; &#60;</span></li>{% endif %}
            {%- if paginator.previous %}<li><a href="{{ paginator.previous | safe }}">&#60;</a></li>{% else %}<li><span class="off">&#60;</span></li>{% endif %}
            {%- for i in range(start=start, end=end+1) %}
                <li>
                  {%- if i == paginator.current_index %}
                  <a class="cnav" href="#">{{i}}</a>
                  {%- elif i > 1 %}
                  <a href="{{ paginator.base_url | safe }}{{ i ~ '/' }}">{{i}}</a>
                  {%- else %}
                  <a href="{{ paginator.first | safe }}">{{ i }}</a>
                  {%- endif %}
                </li>
            {%- endfor %}
            {%- if paginator.next %}<li><a href="{{ paginator.next | safe }}">&#62;</a></li>{% else %}<li><span class="off">&#62;</span></li>{% endif %}
            {%- if paginator.next %}<li><a href="{{ paginator.last | safe }}">&#62; &#124;</a></li>{% else %}<li><span class="off">&#62; &#124;</span></li>{% endif %}
          </ul>
      </nav>
  {%- endif %}
{%- endmacro %}