Merge pull request #14 from LASSAT-YU/master

Allow user to control how many headings are needed before it shows in the nav
This commit is contained in:
Roman 2022-08-24 15:11:57 +02:00 committed by GitHub
commit 76ff110bad
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 4 deletions

View file

@ -18,4 +18,7 @@ easydocs_logo_always_clickable = false
# Notes:
# - Also requries the base URL to be set to the local folder where the site is stored eg. base_url = /home/user/mysite/public/
# - This is not portable and only works with a specific local folder
easydocs_uglyurls = false
easydocs_uglyurls = false
# Minimum number of headings needed on a page before the headings show in the navigation on the left. Defaults to 5.
easydocs_heading_threshold = 5

View file

@ -30,7 +30,7 @@
{% endif -%}
<main>
{# Create variable to allow appending index.html at end of links if set in config #}
{% if not config.extra.easydocs_uglyurls or config.mode == "Serve" -%}
{% if not config.extra.easydocs_uglyurls or config.mode == "serve" -%}
{% set _ugly_url = "" -%}
{% else %}
{% set _ugly_url = "index.html" -%}
@ -81,6 +81,7 @@
{% if current_path == page.path -%}
{# Count number of headers on page #}
{% set_global header_count = 0 -%}
{% for h2 in page.toc -%}
{% set_global header_count = header_count + 1 -%}
@ -92,11 +93,20 @@
{% endfor -%}
{% endfor -%}
{% if header_count > 4 -%}
{# Output headers if above threshold #}
{% if not config.extra.easydocs_heading_threshold -%}
{# Undefined or 0 unable to find a way to differnciate between 0 and undefined.
1 is already including any headings so is not 0 not needed #}
{% set _threshold = 5 -%}
{% else %}
{% set _threshold = config.extra.easydocs_heading_threshold -%}
{% endif -%}
{% if header_count >= _threshold -%}
<ul id="toc">
{% for h2 in page.toc -%}
<li><a href="
{{ h2.permalink | safe }}{{ _ugly_url }}">{{ h2.title }}</a>
{{ h2.permalink | safe }}">{{ h2.title }}</a>
{% if h2.children -%}
<ul>
{% for h3 in h2.children -%}