diff options
| author | Yehonal <yehonal.azeroth@gmail.com> | 2020-01-12 19:20:51 +0100 |
|---|---|---|
| committer | Yehonal <yehonal.azeroth@gmail.com> | 2020-01-12 19:20:51 +0100 |
| commit | a66783cef7766aea9137c09f753563b7a29cabe9 (patch) | |
| tree | 0276ca2f546828bccb45318421013b0fc25512b3 /_includes | |
| parent | 69655922dc8fada82e347b4598c53b784e370e20 (diff) | |
| download | wiki-a66783cef7766aea9137c09f753563b7a29cabe9.tar.gz wiki-a66783cef7766aea9137c09f753563b7a29cabe9.tar.bz2 wiki-a66783cef7766aea9137c09f753563b7a29cabe9.zip | |
Improved TOC
Added title and minHeaders parameters
Diffstat (limited to '_includes')
| -rw-r--r-- | _includes/git-wiki/components/toc/toc-lib.html | 33 | ||||
| -rw-r--r-- | _includes/git-wiki/components/toc/toc.html | 5 |
2 files changed, 24 insertions, 14 deletions
diff --git a/_includes/git-wiki/components/toc/toc-lib.html b/_includes/git-wiki/components/toc/toc-lib.html index 4aa9c88..8851400 100644 --- a/_includes/git-wiki/components/toc/toc-lib.html +++ b/_includes/git-wiki/components/toc/toc-lib.html @@ -12,15 +12,17 @@ * html (string) - the HTML of compiled markdown generated by kramdown in Jekyll Optional Parameters: - * sanitize (bool) : false - when set to true, the headers will be stripped of any HTML in the TOC - * class (string) : '' - a CSS class assigned to the TOC - * id (string) : '' - an ID to assigned to the TOC - * 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 - * ordered (bool) : false - when set to true, an ordered list will be outputted instead of an unordered list - * item_class (string) : '' - add custom class(es) for each list item; has support for '%level%' placeholder, which is the current heading level - * baseurl (string) : '' - add a base url to the TOC links for when your TOC is on another page than the actual content - * anchor_class (string) : '' - add custom class(es) for each anchor element + * title (string) : Contents: - title for the TOC + * minHeaders (int) : 1 - minimum number of headers required to show the TOC + * sanitize (bool) : false - when set to true, the headers will be stripped of any HTML in the TOC + * class (string) : '' - a CSS class assigned to the TOC + * id (string) : '' - an ID to assigned to the TOC + * 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 + * ordered (bool) : false - when set to true, an ordered list will be outputted instead of an unordered list + * item_class (string) : '' - add custom class(es) for each list item; has support for '%level%' placeholder, which is the current heading level + * baseurl (string) : '' - add a base url to the TOC links for when your TOC is on another page than the actual content + * 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 @@ -28,6 +30,8 @@ {% endcomment %} {% capture my_toc %}{% endcapture %} + {% assign title = include.title | default: "Contents:" %} + {% assign minHeaders = include.minHeaders | default: 1 %} {% assign orderedList = include.ordered | default: false %} {% assign minHeader = include.h_min | default: 1 %} {% assign maxHeader = include.h_max | default: 6 %} @@ -36,6 +40,8 @@ {% capture listModifier %}{% if orderedList %}1.{% else %}-{% endif %}{% endcapture %} + {% assign hCount = 0 %} + {% for node in nodes %} {% if node == "" %} {% continue %} @@ -79,6 +85,8 @@ {% capture listItemClass %}{:.{{ include.item_class | replace: '%level%', headerLevel }}}{% endcapture %} {% endif %} + {% assign hCount = hCount | plus: 1 %} + {% capture heading_body %}{% if include.sanitize %}{{ header | strip_html }}{% else %}{{ header }}{% endif %}{% endcapture %} {% capture my_toc %}{{ my_toc }} {{ space }}{{ listModifier }} {{ listItemClass }} [{{ heading_body | replace: "|", "\|" }}]({% if include.baseurl %}{{ include.baseurl }}{% endif %}#{{ html_id }}){% if include.anchor_class %}{:.{{ include.anchor_class }}}{% endif %}{% endcapture %} @@ -93,4 +101,9 @@ {% capture my_toc %}{: #{{ include.id }}} {{ my_toc | lstrip }}{% endcapture %} {% endif %} -{% endcapture %}{% assign tocWorkspace = '' %}{{ my_toc | markdownify | strip }}
\ No newline at end of file +{% endcapture %}{% assign tocWorkspace = '' %} + +{% if hCount >= minHeaders %} + {{ title }} + {{ my_toc | markdownify | strip }} +{% endif %}
\ No newline at end of file diff --git a/_includes/git-wiki/components/toc/toc.html b/_includes/git-wiki/components/toc/toc.html index c354b42..7329f40 100644 --- a/_includes/git-wiki/components/toc/toc.html +++ b/_includes/git-wiki/components/toc/toc.html @@ -2,10 +2,7 @@ {% include {{ site.inc_before_toc }} %} {% endif %} -<div> - <p>Contents:</p> - {% include git-wiki/components/toc/toc-lib.html html=content sanitize=true class="inline_toc" id="git-wiki-toc" h_min=1 h_max=3 ordered=1 %} -</div> +{% include git-wiki/components/toc/toc-lib.html title="Contents:" minHeaders=1 html=content sanitize=true class="inline_toc" id="git-wiki-toc" h_min=1 h_max=3 ordered=1 %} {% if site.inc_after_toc %} {% include {{ site.inc_after_toc }} %} |
