{% comment %}
Adapted from: https://github.com/allejo/jekyll-toc
Usage:
{% include_cached toc.html path=dir class="inline_toc" h_min=2 h_max=3 %}
Optional Parameters:
* path (string) : '' - the path of the files for the toc to be generated
* h_min (int) : 1 - the minimum TOC header level to use; any header lower than this value will be ignored
* h_max (int) : 6 - the maximum TOC header level to use; any header greater than this value will be ignored
* item_class (string) : '' - add custom class(es) for each list item; has support for '%level%' placeholder, which is the current heading level
* anchor_class (string) : '' - add custom class(es) for each anchor element
Output:
An ordered or unordered list representing the table of contents of a markdown block. This snippet will only
generate the table of contents and will NOT output the markdown given to it
{% endcomment %}
{% assign unsorted_pages = "" | split: ',' %}
{% assign sorted_pages = site.html_pages | sort: 'name' %}
{% for site_page in sorted_pages %}
{% unless site_page.exclude %}
{% if include.path == null %}
{% assign unsorted_pages = unsorted_pages | push: site_page %}
{% else %}
{% assign site_page_folder = site_page.dir | uri_escape | remove_first: '/' | split: '/' | first | prepend: '/' %}
{% if site_page_folder != '/' %}
{% assign site_page_folder = site_page_folder | append: '/' %}
{% endif %}
{% if site_page_folder == include.path %}
{% assign unsorted_pages = unsorted_pages | push: site_page %}
{% endif %}
{% endif %}
{% endunless %}
{% endfor %}
{% comment %}
Page ordering
{% endcomment %}
{% capture page_order %}
{% include document-title.txt dir=include.path info="order" %}
{% endcapture %}
{% assign page_order = page_order | strip | split: '/' %}
{% if page_order.size > 0 %}
{% assign pages = '' | split: ',' %}
{% for order in page_order %}
{% for unsorted_page in unsorted_pages %}
{% if unsorted_page.title == order or unsorted_page.name == order %}
{% assign pages = pages | push: unsorted_page %}
{% endif %}
{% endfor %}
{% endfor %}
{% else %}
{% assign pages = unsorted_pages | sort: 'name' %}
{% endif %}
{% capture tocWorkspace %}
{% capture my_toc %}{% endcapture %}
{% assign orderedList = include.ordered | default: false %}
{% assign minHeader = include.h_min | default: 1 %}
{% assign maxHeader = include.h_max | default: 6 %}
{% assign firstHeader = true %}
{% for page in pages %}
{% assign nodes = page.content | markdownify | split: ' maxHeader %}
{% continue %}
{% endif %}
{% if firstHeader %}
{% assign firstHeader = false %}
{% assign minHeader = headerLevel %}
{% endif %}
{% assign indentAmount = headerLevel | minus: minHeader | add: 1 %}
{% assign _workspace = node | split: '' | first }}>{% endcapture %}
{% assign header = _workspace[0] | replace: _hAttrToStrip, '' %}
{% comment %}
Strips out footnotes links then strips out all other html tags
This naively assumes that all footnote links are appended at the end of the header
{% endcomment %}
{% assign header = header | split: ' {{ header }} {% endcapture %}
{% endfor %}
{% endfor %}
{% if include.class %}
{% capture my_toc %}{:.{{ include.class }}}
{{ my_toc | lstrip }}{% endcapture %}
{% endif %}
{% endcapture %}{% assign tocWorkspace = '' %}{{ my_toc | markdownify | strip }}