Improve TOC logic, reduce code duplication and add changelog entries
This commit is contained in:
@ -5,11 +5,11 @@
|
||||
{%- set date_locale = macros_translate::translate(key="date_locale", default="en_US", language_strings=language_strings) -%}
|
||||
{%- set rel_attributes = macros_rel_attributes::rel_attributes() | trim -%}
|
||||
|
||||
{% if config.extra.toc.numbered %}
|
||||
{% set list_element = "ol" %}
|
||||
{% else %}
|
||||
{% set list_element = "ul" %}
|
||||
{% endif %}
|
||||
{%- if page.extra.toc_ordered or section.extra.toc_ordered or config.extra.toc_ordered -%}
|
||||
{%- set list_element = "ol" -%}
|
||||
{%- else -%}
|
||||
{%- set list_element = "ul" -%}
|
||||
{%- endif -%}
|
||||
|
||||
<article>
|
||||
{%- if page.extra.banner -%}
|
||||
@ -77,28 +77,28 @@
|
||||
</div>
|
||||
|
||||
<div id="buttons-container">
|
||||
{%- if page.extra.toc and config.extra.toc.popup -%}
|
||||
{%- if page.extra.toc and page.toc | length > 0 -%}
|
||||
<details id="toc" class="closable">
|
||||
<summary title="{{ macros_translate::translate(key='table_of_contents', default='Table of Contents', language_strings=language_strings) }}"><i class="icon"></i></summary>
|
||||
<div id="toc-dropdown">
|
||||
<strong>{{ macros_translate::translate(key="table_of_contents", default="Table of Contents", language_strings=language_strings) }}</strong>
|
||||
<div>
|
||||
<{{list_element}}>
|
||||
<{{ list_element }}>
|
||||
{%- for h1 in page.toc -%}
|
||||
<li>
|
||||
<a href="{{ h1.permalink | safe }}">{{ h1.title }}</a>
|
||||
{%- if h1.children -%}
|
||||
<{{list_element}}>
|
||||
<{{ list_element }}>
|
||||
{%- for h2 in h1.children -%}
|
||||
<li>
|
||||
<a href="{{ h2.permalink | safe }}">{{ h2.title }}</a>
|
||||
</li>
|
||||
{%- endfor -%}
|
||||
</{{list_element}}>
|
||||
</{{ list_element }}>
|
||||
{%- endif -%}
|
||||
</li>
|
||||
{%- endfor -%}
|
||||
</{{list_element}}>
|
||||
</{{ list_element }}>
|
||||
</div>
|
||||
</div>
|
||||
</details>
|
||||
@ -114,26 +114,10 @@
|
||||
|
||||
{%- include "partials/statements.html" -%}
|
||||
|
||||
|
||||
{%- if page.extra.toc and config.extra.toc.inline-%}
|
||||
<h2>{{ macros_translate::translate(key="table_of_contents", default="Table of Contents", language_strings=language_strings) }}</h2>
|
||||
|
||||
<{{list_element}} role="list">
|
||||
{%- for h1 in page.toc -%}
|
||||
<li>
|
||||
<a href="{{ h1.permalink | safe }}">{{ h1.title }}</a>
|
||||
{%- if h1.children -%}
|
||||
<{{list_element}} role="list">
|
||||
{%- for h2 in h1.children -%}
|
||||
<li>
|
||||
<a href="{{ h2.permalink | safe }}">{{ h2.title }}</a>
|
||||
</li>
|
||||
{%- endfor -%}
|
||||
</{{list_element}}>
|
||||
{%- endif -%}
|
||||
</li>
|
||||
{%- endfor -%}
|
||||
</{{list_element}}>
|
||||
{%- if page.extra.toc_inline -%}
|
||||
{%- include "partials/toc.html" -%}
|
||||
{%- elif config.extra.toc_inline -%}
|
||||
{%- include "partials/toc.html" -%}
|
||||
{%- endif -%}
|
||||
|
||||
{{ page.content | safe }}
|
||||
|
@ -1,37 +1,33 @@
|
||||
{%- if page.extra.toc -%}
|
||||
<h2>{{ macros_translate::translate(key="table_of_contents", default="Table of Contents", language_strings=language_strings) }}</h2>
|
||||
<ul>
|
||||
{%- for h1 in page.toc -%}
|
||||
<li>
|
||||
<a href="{{ h1.permalink | safe }}">{{ h1.title }}</a>
|
||||
{%- if h1.children -%}
|
||||
<ul>
|
||||
{%- for h2 in h1.children -%}
|
||||
<li>
|
||||
<a href="{{ h2.permalink | safe }}">{{ h2.title }}</a>
|
||||
</li>
|
||||
{%- endfor -%}
|
||||
</ul>
|
||||
{%- endif -%}
|
||||
</li>
|
||||
{%- endfor -%}
|
||||
</ul>
|
||||
{%- elif section.extra.toc -%}
|
||||
<h2>{{ macros_translate::translate(key="table_of_contents", default="Table of Contents", language_strings=language_strings) }}</h2>
|
||||
<ul>
|
||||
{%- for h1 in section.toc -%}
|
||||
<li>
|
||||
<a href="{{ h1.permalink | safe }}">{{ h1.title }}</a>
|
||||
{%- if h1.children -%}
|
||||
<ul>
|
||||
{%- for h2 in h1.children -%}
|
||||
<li>
|
||||
<a href="{{ h2.permalink | safe }}">{{ h2.title }}</a>
|
||||
</li>
|
||||
{%- endfor -%}
|
||||
</ul>
|
||||
{%- endif -%}
|
||||
</li>
|
||||
{%- endfor -%}
|
||||
</ul>
|
||||
{%- if page.extra.toc_ordered or section.extra.toc_ordered or config.extra.toc_ordered -%}
|
||||
{%- set list_element = "ol" -%}
|
||||
{%- else -%}
|
||||
{%- set list_element = "ul" -%}
|
||||
{%- endif -%}
|
||||
|
||||
{%- if page.toc -%}
|
||||
{%- set toc = page.toc -%}
|
||||
{%- elif section.toc -%}
|
||||
{%- set toc = section.toc -%}
|
||||
{%- endif -%}
|
||||
|
||||
{%- if page.extra.toc or section.extra.toc -%}
|
||||
{%- if toc | length > 0 -%}
|
||||
<h2>{{ macros_translate::translate(key="toc", default="Table of Contents", language_strings=language_strings) }}</h2>
|
||||
<{{ list_element }}>
|
||||
{%- for h1 in toc -%}
|
||||
<li>
|
||||
<a href="{{ h1.permalink | safe }}">{{ h1.title }}</a>
|
||||
{%- if h1.children -%}
|
||||
<{{ list_element }}>
|
||||
{%- for h2 in h1.children -%}
|
||||
<li>
|
||||
<a href="{{ h2.permalink | safe }}">{{ h2.title }}</a>
|
||||
</li>
|
||||
{%- endfor -%}
|
||||
</{{ list_element }}>
|
||||
{%- endif -%}
|
||||
</li>
|
||||
{%- endfor -%}
|
||||
</{{ list_element }}>
|
||||
{%- endif -%}
|
||||
{%- endif -%}
|
||||
|
Reference in New Issue
Block a user