Skip to content

Instantly share code, notes, and snippets.

@letrastudio
Created July 18, 2018 18:05
Show Gist options
  • Save letrastudio/8a59e12f65f1ffa78f0e699c0bc3d155 to your computer and use it in GitHub Desktop.
Save letrastudio/8a59e12f65f1ffa78f0e699c0bc3d155 to your computer and use it in GitHub Desktop.
{% assign heading_level = "2" %}
{% assign opening_tag = "<h" | append: heading_level %}
{% assign closing_tag = "</h" | append: heading_level | append: ">" %}
{% assign toc = content | split: opening_tag %}
<nav class="page-toc">
<ol>
{% for item in toc %}
{% if item contains closing_tag %}
{% assign tag = item | split: closing_tag | first | strip %}
{% assign attrs = tag | split: ">" | first | strip %}
{% assign id = attrs | split: "id=" | last | split: " " | first | remove: "'" | remove: '"' | strip %}
{% assign title = tag | split: ">" | last | strip %}
<li><a href="#{{ id }}">{{ title }}</a></li>
{% endif %}
{% endfor %}
</ol>
</nav>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment