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--- config.toml | 1 + sass/abridge.scss | 17 ++++++++- templates/macros/macros.html | 9 +++++ templates/page.html | 86 +++++++++++++++++++++++++++++++++++++------- 4 files changed, 100 insertions(+), 13 deletions(-) diff --git a/config.toml b/config.toml index fa1b3cf..aa283a6 100644 --- a/config.toml +++ b/config.toml @@ -119,6 +119,7 @@ toc = true recent = true # TOC / index recent_items = 15 series = true +section_items = 10 # Max amount of section items allowed to displayed in a list, use 0 to disable #Series_parts = "$NUMBER_OF_PARTS part Series" meta_index = { position="bottom", size="s90", author=false, readtime=false, readstring="min", date=true, updated=false, categories_tags=true, divider="" } diff --git a/sass/abridge.scss b/sass/abridge.scss index a4190b2..cf6960a 100644 --- a/sass/abridge.scss +++ b/sass/abridge.scss @@ -1182,6 +1182,21 @@ $syntax: true !default;//syntax highlighting for code blocks max-width: 30rem; margin: var(--s2) auto; } + + // Hides the next .hidden_li element when details is closed + details:not([open]) + .hidden_li { + height: 0; + visibility: hidden; + overflow: hidden; + } + + summary { + margin-left: -1em; + margin-bottom: .2rem; + color: var(--c4); + } + + .blockdiv { border-radius: var(--br); border-top: 5px solid var(--a1); @@ -1575,4 +1590,4 @@ $syntax: true !default;//syntax highlighting for code blocks //.z-variable.z-language.z-fenced.z-markdown { // color: var(--h1); //} -} +} \ No newline at end of file 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 %} -
    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