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/macros/macros.html | 9 +++++
templates/page.html | 86 +++++++++++++++++++++++++++++++++++++-------
2 files changed, 83 insertions(+), 12 deletions(-)
(limited to 'templates')
diff --git a/templates/macros/macros.html b/templates/macros/macros.html
index 66673d1..d5ea391 100644
--- a/templates/macros/macros.html
+++ b/templates/macros/macros.html
@@ -297,3 +297,12 @@
{%- endif %}
{%- endmacro %}
+
+{%- macro series_link(inner, page) %}
+ {%- set uglyurls = config.extra.uglyurls | default(value=false) -%}
+ {%- if inner.content == page.content %}
+
{{ inner.title }}
+ {% else %}
+ {{ inner.title }}
+ {%- endif %}
+{%- endmacro %}
\ No newline at end of file
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 %}
- - {{ inner.title }}
- {% else %}
- - {{ inner.title }}
- {%- endif %}
+ {%- if inner.content == page.content %}
+ - {{ inner.title }}
+ {%- set_global current_section_index = loop.index0 %} {# Finds the current section, needed for pagination logic later #}
+ {% else %}
+ - {{ inner.title }}
+ {%- 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 %}
- - {{ inner.title }}
- {% else %}
- - {{ inner.title }}
+ {%- 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)) %}
+
- {{ inner.title }}
+ {%- 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) %}
+ - {{ inner.title }}
+ {%- 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 ) %}
+ - {{ inner.title }}
+ {%- endfor %}
+
+ {%- if current_section_index < num_pages - 4 %}
+
+ More...
+
+
+ {%- for inner in sorted_array | slice(start=(current_section_index + 3), end=(num_pages - 1)) %}
+
- {{ inner.title }}
+ {%- 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