quitsocialmedia.club/_includes/toc.html

130 lines
5.4 KiB
HTML
Raw Normal View History

2020-09-17 14:41:50 +02:00
{% capture tocWorkspace %}
2020-12-31 20:03:57 +01:00
{% capture newline %}
{% endcapture %}
{% assign newline = newline | rstrip %} <!-- Remove the extra spacing but preserve the newline -->
{% capture deprecation_warnings %}{% endcapture %}
{% if include.baseurl %}
{% capture deprecation_warnings %}{{ deprecation_warnings }}<!-- jekyll-toc :: "baseurl" has been deprecated, use "base_url" instead -->{{ newline }}{% endcapture %}
{% endif %}
{% if include.skipNoIDs %}
{% capture deprecation_warnings %}{{ deprecation_warnings }}<!-- jekyll-toc :: "skipNoIDs" has been deprecated, use "skip_no_ids" instead -->{{ newline }}{% endcapture %}
{% endif %}
{% capture jekyll_toc %}{% endcapture %}
2020-09-17 14:41:50 +02:00
{% assign orderedList = include.ordered | default: false %}
2020-12-31 20:03:57 +01:00
{% assign baseURL = include.base_url | default: include.baseurl | default: '' %}
{% assign skipNoIDs = include.skip_no_ids | default: include.skipNoIDs | default: false %}
{% assign minHeader = 2 %}
{% assign maxHeader = 6 %}
{% assign nodes = include.html | strip | split: '<h' %}
2020-09-17 14:41:50 +02:00
{% assign firstHeader = true %}
2020-12-31 20:03:57 +01:00
{% assign currLevel = 0 %}
{% assign lastLevel = 0 %}
2020-09-17 14:41:50 +02:00
2020-12-31 20:03:57 +01:00
{% capture listModifier %}{% if orderedList %}ol{% else %}ul{% endif %}{% endcapture %}
2020-09-17 14:41:50 +02:00
{% for node in nodes %}
{% if node == "" %}
{% continue %}
{% endif %}
2020-12-31 20:03:57 +01:00
{% assign currLevel = node | replace: '"', '' | slice: 0, 1 | times: 1 %}
2020-09-17 14:41:50 +02:00
2020-12-31 20:03:57 +01:00
{% if currLevel < minHeader or currLevel > maxHeader %}
2020-09-17 14:41:50 +02:00
{% continue %}
{% endif %}
{% assign _workspace = node | split: '</h' %}
{% assign _idWorkspace = _workspace[0] | split: 'id="' %}
{% assign _idWorkspace = _idWorkspace[1] | split: '"' %}
2020-12-31 20:03:57 +01:00
{% assign htmlID = _idWorkspace[0] %}
2020-09-17 14:41:50 +02:00
{% assign _classWorkspace = _workspace[0] | split: 'class="' %}
{% assign _classWorkspace = _classWorkspace[1] | split: '"' %}
2020-12-31 20:03:57 +01:00
{% assign htmlClass = _classWorkspace[0] %}
2020-09-17 14:41:50 +02:00
2020-12-31 20:03:57 +01:00
{% if htmlClass contains "no_toc" %}
2020-09-17 14:41:50 +02:00
{% continue %}
{% endif %}
2020-12-31 20:03:57 +01:00
{% if firstHeader %}
{% assign minHeader = currLevel %}
{% endif %}
2020-09-17 14:41:50 +02:00
{% capture _hAttrToStrip %}{{ _workspace[0] | split: '>' | first }}>{% endcapture %}
{% assign header = _workspace[0] | replace: _hAttrToStrip, '' %}
{% if include.item_class and include.item_class != blank %}
2020-12-31 20:03:57 +01:00
{% capture listItemClass %} class="{{ include.item_class | replace: '%level%', currLevel | split: '.' | join: ' ' }}"{% endcapture %}
2020-09-17 14:41:50 +02:00
{% endif %}
2020-12-31 20:03:57 +01:00
{% if include.submenu_class and include.submenu_class != blank %}
{% assign subMenuLevel = currLevel | minus: 1 %}
{% capture subMenuClass %} class="{{ include.submenu_class | replace: '%level%', subMenuLevel | split: '.' | join: ' ' }}"{% endcapture %}
{% endif %}
2020-09-17 14:41:50 +02:00
2020-12-31 20:03:57 +01:00
{% capture anchorBody %}{% if include.sanitize %}{{ header | strip_html }}{% else %}{{ header }}{% endif %}{% endcapture %}
{% if htmlID %}
{% capture anchorAttributes %} href="{% if baseURL %}{{ baseURL }}{% endif %}#{{ htmlID }}"{% endcapture %}
{% if include.anchor_class %}
{% capture anchorAttributes %}{{ anchorAttributes }} class="{{ include.anchor_class | split: '.' | join: ' ' }}"{% endcapture %}
{% endif %}
{% capture listItem %}<a{{ anchorAttributes }}>{{ anchorBody }}</a>{% endcapture %}
{% elsif skipNoIDs == true %}
{% continue %}
{% else %}
{% capture listItem %}{{ anchorBody }}{% endcapture %}
{% endif %}
{% if currLevel > lastLevel %}
{% capture jekyll_toc %}{{ jekyll_toc }}<{{ listModifier }}{{ subMenuClass }}>{% endcapture %}
{% elsif currLevel < lastLevel %}
{% assign repeatCount = lastLevel | minus: currLevel %}
{% for i in (1..repeatCount) %}
{% capture jekyll_toc %}{{ jekyll_toc }}</li></{{ listModifier }}>{% endcapture %}
{% endfor %}
{% capture jekyll_toc %}{{ jekyll_toc }}</li>{% endcapture %}
2020-09-17 14:41:50 +02:00
{% else %}
2020-12-31 20:03:57 +01:00
{% capture jekyll_toc %}{{ jekyll_toc }}</li>{% endcapture %}
2020-09-17 14:41:50 +02:00
{% endif %}
2020-12-31 20:03:57 +01:00
{% capture jekyll_toc %}{{ jekyll_toc }}<li{{ listItemClass }}>{{ listItem }}{% endcapture %}
{% assign lastLevel = currLevel %}
{% assign firstHeader = false %}
2020-09-17 14:41:50 +02:00
{% endfor %}
2020-12-31 20:03:57 +01:00
{% assign repeatCount = minHeader | minus: 1 %}
{% assign repeatCount = lastLevel | minus: repeatCount %}
{% for i in (1..repeatCount) %}
{% capture jekyll_toc %}{{ jekyll_toc }}</li></{{ listModifier }}>{% endcapture %}
{% endfor %}
{% if jekyll_toc != '' %}
{% assign rootAttributes = '' %}
{% if include.class and include.class != blank %}
{% capture rootAttributes %} class="{{ include.class | split: '.' | join: ' ' }}"{% endcapture %}
{% endif %}
{% if include.id and include.id != blank %}
{% capture rootAttributes %}{{ rootAttributes }} id="{{ include.id }}"{% endcapture %}
{% endif %}
2020-09-17 14:41:50 +02:00
2020-12-31 20:03:57 +01:00
{% if rootAttributes %}
{% assign nodes = jekyll_toc | split: '>' %}
{% capture jekyll_toc %}<{{ listModifier }}{{ rootAttributes }}>{{ nodes | shift | join: '>' }}>{% endcapture %}
{% endif %}
2020-09-17 14:41:50 +02:00
{% endif %}
2020-12-31 20:03:57 +01:00
{% endcapture %}{% assign tocWorkspace = '' %}{{ deprecation_warnings }}{{ jekyll_toc }}