From 0e3727b97a6297ac9cdbbf3753a301c182e356d6 Mon Sep 17 00:00:00 2001 From: Hysterelius Date: Tue, 26 Sep 2023 14:36:59 +1000 Subject: Add collapsing for sections (#148) Add collapsing for sections--- templates/page.html | 86 +++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 74 insertions(+), 12 deletions(-) (limited to 'templates/page.html') diff --git a/templates/page.html b/templates/page.html index 6aac7e1..d7abe0b 100644 --- a/templates/page.html +++ b/templates/page.html @@ -63,11 +63,12 @@ {{ tag.name }} ({{ parts_string }})
    {%- for inner in tag.pages | sort(attribute="date") %} - {%- if inner.content == page.content %} -
  1. {{ inner.title }}
  2. - {% else %} -
  3. {{ inner.title }}
  4. - {%- endif %} + {%- if inner.content == page.content %} +
  5. {{ inner.title }}
  6. + {%- set_global current_section_index = loop.index0 %} {# Finds the current section, needed for pagination logic later #} + {% else %} +
  7. {{ inner.title }}
  8. + {%- endif %} {%- endfor %}
@@ -101,17 +102,78 @@ {%- if toc %}
- {%- if page.extra.section %} + {%- if page.extra.section %} + {%- set num_extra_pages = config.extra.section_items | default(value=5) %}
{{ parts_string }}
    - {%- for inner in tag.pages | sort(attribute="date") %} - {%- if inner.content == page.content %} -
  1. {{ inner.title }}
  2. - {% else %} -
  3. {{ inner.title }}
  4. + {%- if tag.page_count > num_extra_pages and num_extra_pages > 0 %} + {%- set sorted_array = tag.pages | sort(attribute="date") %} + {%- set num_pages = tag.page_count %} + + {# Shows the first page #} + {{ macros::series_link(inner=sorted_array.0, page=page) }} + + {# Hides the next couple of pages if the current section is more than 3 away from start #} + {%- if current_section_index > 3 %} +
    + More... +
    +
    + {%- for inner in sorted_array | slice(start=1, end=(current_section_index - 2)) %} +
  5. {{ inner.title }}
  6. + {%- endfor %} +
    + {%- endif %} + + {# Max(current_section_index - 2, 1) #} + {%- if (current_section_index - 2 ) > 1 %} + {%- set num = current_section_index - 2 %} + {%- else %} + {%- set num = 1 %} + {%- endif %} + + {# Shows two pages before current page #} + {%- for inner in sorted_array | slice(start=num, end=current_section_index) %} +
  7. {{ inner.title }}
  8. + {%- endfor %} + + {# Shows the current page #} + {%- if current_section_index != 0 and current_section_index != (num_pages - 1) %} + {{ macros::series_link(inner=sorted_array[current_section_index], page=page) }} + {%- endif %} + + {# Min(num_pages - 1, current_section_index + 3) #} + {%- if (num_pages - 2 ) < (current_section_index + 3) %} + {%- set num = num_pages - 1 %} + {%- else %} + {%- set num = current_section_index + 3 %} + {%- endif %} + + {%- for inner in sorted_array | slice(start=(current_section_index + 1), end=num ) %} +
  9. {{ inner.title }}
  10. + {%- endfor %} + + {%- if current_section_index < num_pages - 4 %} +
    + More... +
    +
    + {%- for inner in sorted_array | slice(start=(current_section_index + 3), end=(num_pages - 1)) %} +
  11. {{ inner.title }}
  12. + {%- endfor %} +
    + {%- endif %} + + {%- set last = num_pages - 1%} + {{ macros::series_link(inner=sorted_array[last], page=page) }} + + {# If there is not more than max pages render normally #} + {%- else %} + {%- for inner in tag.pages | sort(attribute="date") %} + {{ macros::series_link(inner=inner, page=page) }} + {%- endfor %} {%- endif %} - {%- endfor %}
{%- endif %} -- cgit v1.3.1