minimal-mistakes-jekyll 4.20.1 → 4.24.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +91 -1
  3. data/README.md +11 -10
  4. data/_data/ui-text.yml +194 -24
  5. data/_includes/archive-single.html +2 -2
  6. data/_includes/category-list.html +2 -9
  7. data/_includes/comments-providers/giscus.html +24 -0
  8. data/_includes/comments-providers/scripts.html +2 -0
  9. data/_includes/comments.html +4 -1
  10. data/_includes/documents-collection.html +6 -12
  11. data/_includes/figure +2 -2
  12. data/_includes/footer.html +3 -1
  13. data/_includes/head.html +5 -17
  14. data/_includes/masthead.html +2 -4
  15. data/_includes/page__date.html +3 -2
  16. data/_includes/page__hero.html +7 -3
  17. data/_includes/page__meta.html +31 -0
  18. data/_includes/seo.html +6 -0
  19. data/_includes/skip-links.html +0 -1
  20. data/_includes/tag-list.html +2 -9
  21. data/_includes/toc.html +128 -42
  22. data/_layouts/categories.html +3 -2
  23. data/_layouts/category.html +3 -2
  24. data/_layouts/collection.html +3 -2
  25. data/_layouts/default.html +2 -2
  26. data/_layouts/posts.html +3 -2
  27. data/_layouts/search.html +2 -2
  28. data/_layouts/single.html +2 -2
  29. data/_layouts/tag.html +3 -2
  30. data/_layouts/tags.html +3 -2
  31. data/_sass/minimal-mistakes.scss +2 -2
  32. data/_sass/minimal-mistakes/_archive.scss +8 -0
  33. data/_sass/minimal-mistakes/_footer.scss +0 -1
  34. data/_sass/minimal-mistakes/_forms.scss +0 -34
  35. data/_sass/minimal-mistakes/_navigation.scss +7 -0
  36. data/_sass/minimal-mistakes/_notices.scss +5 -5
  37. data/_sass/minimal-mistakes/_page.scss +1 -1
  38. data/_sass/minimal-mistakes/_sidebar.scss +0 -1
  39. data/_sass/minimal-mistakes/_variables.scss +4 -0
  40. data/_sass/minimal-mistakes/skins/_aqua.scss +5 -1
  41. data/_sass/minimal-mistakes/skins/_contrast.scss +2 -1
  42. data/_sass/minimal-mistakes/skins/_dark.scss +4 -2
  43. data/_sass/minimal-mistakes/skins/_mint.scss +1 -0
  44. data/_sass/minimal-mistakes/skins/_neon.scss +7 -1
  45. data/_sass/minimal-mistakes/skins/_plum.scss +7 -1
  46. data/_sass/minimal-mistakes/skins/_sunrise.scss +7 -2
  47. data/assets/js/_main.js +2 -2
  48. data/assets/js/lunr/lunr-store.js +2 -2
  49. data/assets/js/lunr/lunr.js +67 -76
  50. data/assets/js/lunr/lunr.min.js +6 -1
  51. data/assets/js/main.min.js +3 -6
  52. data/assets/js/plugins/jquery.greedy-navigation.js +67 -14
  53. data/assets/js/vendor/jquery/{jquery-3.4.1.js → jquery-3.5.1.js} +756 -482
  54. metadata +5 -4
  55. data/_includes/post__meta.html +0 -35
@@ -6,19 +6,12 @@
6
6
  {% endcase %}
7
7
 
8
8
  {% if site.category_archive.path %}
9
- {% comment %}
10
- <!-- Sort alphabetically regardless of case e.g. a B c d E -->
11
- <!-- modified from http://www.codeofclimber.ru/2015/sorting-site-tags-in-jekyll/ -->
12
- {% endcomment %}
13
- {% capture page_categories %}{% for category in page.categories %}{{ category | downcase }}|{{ category }}{% unless forloop.last %},{% endunless %}{% endfor %}{% endcapture %}
14
- {% assign category_hashes = page_categories | split: ',' | sort %}
9
+ {% assign categories_sorted = page.categories | sort_natural %}
15
10
 
16
11
  <p class="page__taxonomy">
17
12
  <strong><i class="fas fa-fw fa-folder-open" aria-hidden="true"></i> {{ site.data.ui-text[site.locale].categories_label | default: "Categories:" }} </strong>
18
13
  <span itemprop="keywords">
19
- {% for hash in category_hashes %}
20
- {% assign keyValue = hash | split: '|' %}
21
- {% capture category_word %}{{ keyValue[1] | strip_newlines }}{% endcapture %}
14
+ {% for category_word in categories_sorted %}
22
15
  <a href="{{ category_word | slugify | prepend: path_type | prepend: site.category_archive.path | relative_url }}" class="page__taxonomy-item" rel="tag">{{ category_word }}</a>{% unless forloop.last %}<span class="sep">, </span>{% endunless %}
23
16
  {% endfor %}
24
17
  </span>
@@ -0,0 +1,24 @@
1
+ <script>
2
+ 'use strict';
3
+
4
+ (function () {
5
+ var commentContainer = document.querySelector('#giscus-comments');
6
+
7
+ if (!commentContainer) {
8
+ return;
9
+ }
10
+
11
+ var script = document.createElement('script');
12
+ script.setAttribute('src', 'https://giscus.app/client.js');
13
+ script.setAttribute('data-repo', '{{ site.repository | downcase }}');
14
+ script.setAttribute('data-repo-id', '{{ site.comments.giscus.repo_id }}');
15
+ script.setAttribute('data-category', '{{ site.comments.giscus.category_name }}');
16
+ script.setAttribute('data-category-id', '{{ site.comments.giscus.category_id }}');
17
+ script.setAttribute('data-mapping', '{{ site.comments.giscus.discussion_term | default: "pathname" }}');
18
+ script.setAttribute('data-reactions-enabled', '{{ site.comments.giscus.reactions_enabled | default: 1 }}');
19
+ script.setAttribute('data-theme', '{{ site.comments.giscus.theme | default: "light" }}');
20
+ script.setAttribute('crossorigin', 'anonymous');
21
+
22
+ commentContainer.appendChild(script);
23
+ })();
24
+ </script>
@@ -12,6 +12,8 @@
12
12
  {% include /comments-providers/staticman_v2.html %}
13
13
  {% when "utterances" %}
14
14
  {% include /comments-providers/utterances.html %}
15
+ {% when "giscus" %}
16
+ {% include /comments-providers/giscus.html %}
15
17
  {% when "custom" %}
16
18
  {% include /comments-providers/custom_scripts.html %}
17
19
  {% endcase %}
@@ -35,7 +35,7 @@
35
35
  <div class="page__comments-form">
36
36
  <h4 class="page__comments-title">{{ site.data.ui-text[site.locale].comments_label | default: "Leave a Comment" }}</h4>
37
37
  <p class="small">{{ site.data.ui-text[site.locale].comment_form_info | default: "Your email address will not be published. Required fields are marked" }} <span class="required">*</span></p>
38
- <form id="new_comment" class="page__comments-form js-form form" method="post" action="{{ site.comments.staticman.endpoint | default: 'https://api.staticman.net/v2/entry/' }}{{ site.repository }}/{{ site.comments.staticman.branch }}/comments">
38
+ <form id="new_comment" class="page__comments-form js-form form" method="post" action="{{ site.comments.staticman.endpoint }}{{ site.repository }}/{{ site.comments.staticman.branch }}/comments">
39
39
  <div class="form__spinner">
40
40
  <i class="fas fa-spinner fa-spin fa-3x fa-fw"></i>
41
41
  <span class="sr-only">{{ site.data.ui-text[site.locale].loading_label | default: "Loading..." }}</span>
@@ -153,6 +153,9 @@
153
153
  {% when "utterances" %}
154
154
  <h4 class="page__comments-title">{{ comments_label }}</h4>
155
155
  <section id="utterances-comments"></section>
156
+ {% when "giscus" %}
157
+ <h4 class="page__comments-title">{{ comments_label }}</h4>
158
+ <section id="giscus-comments"></section>
156
159
  {% when "custom" %}
157
160
  {% include /comments-providers/custom.html %}
158
161
  {% endcase %}
@@ -1,17 +1,11 @@
1
1
  {% assign entries = site[include.collection] %}
2
2
 
3
- {% if include.sort_by == 'title' %}
4
- {% if include.sort_order == 'reverse' %}
5
- {% assign entries = entries | sort: 'title' | reverse %}
6
- {% else %}
7
- {% assign entries = entries | sort: 'title' %}
8
- {% endif %}
9
- {% elsif include.sort_by == 'date' %}
10
- {% if include.sort_order == 'reverse' %}
11
- {% assign entries = entries | sort: 'date' | reverse %}
12
- {% else %}
13
- {% assign entries = entries | sort: 'date' %}
14
- {% endif %}
3
+ {% if include.sort_by %}
4
+ {% assign entries = entries | sort: include.sort_by %}
5
+ {% endif %}
6
+
7
+ {% if include.sort_order == 'reverse' %}
8
+ {% assign entries = entries | reverse %}
15
9
  {% endif %}
16
10
 
17
11
  {%- for post in entries -%}
data/_includes/figure CHANGED
@@ -1,9 +1,9 @@
1
1
  <figure class="{{ include.class }}">
2
2
  <img src="{{ include.image_path | relative_url }}"
3
3
  alt="{% if include.alt %}{{ include.alt }}{% endif %}">
4
- {% if include.caption %}
4
+ {%- if include.caption -%}
5
5
  <figcaption>
6
6
  {{ include.caption | markdownify | remove: "<p>" | remove: "</p>" }}
7
7
  </figcaption>
8
- {% endif %}
8
+ {%- endif -%}
9
9
  </figure>
@@ -12,7 +12,9 @@
12
12
  {% endfor %}
13
13
  {% endif %}
14
14
 
15
- <li><a href="{% if site.atom_feed.path %}{{ site.atom_feed.path }}{% else %}{{ '/feed.xml' | relative_url }}{% endif %}"><i class="fas fa-fw fa-rss-square" aria-hidden="true"></i> {{ site.data.ui-text[site.locale].feed_label | default: "Feed" }}</a></li>
15
+ {% unless site.atom_feed.hide %}
16
+ <li><a href="{% if site.atom_feed.path %}{{ site.atom_feed.path }}{% else %}{{ '/feed.xml' | relative_url }}{% endif %}"><i class="fas fa-fw fa-rss-square" aria-hidden="true"></i> {{ site.data.ui-text[site.locale].feed_label | default: "Feed" }}</a></li>
17
+ {% endunless %}
16
18
  </ul>
17
19
  </div>
18
20
 
data/_includes/head.html CHANGED
@@ -2,7 +2,9 @@
2
2
 
3
3
  {% include seo.html %}
4
4
 
5
- <link href="{% if site.atom_feed.path %}{{ site.atom_feed.path }}{% else %}{{ '/feed.xml' | relative_url }}{% endif %}" type="application/atom+xml" rel="alternate" title="{{ site.title }} Feed">
5
+ {% unless site.atom_feed.hide %}
6
+ <link href="{% if site.atom_feed.path %}{{ site.atom_feed.path }}{% else %}{{ '/feed.xml' | relative_url }}{% endif %}" type="application/atom+xml" rel="alternate" title="{{ site.title }} Feed">
7
+ {% endunless %}
6
8
 
7
9
  <!-- https://t.co/dKP3o1e -->
8
10
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
@@ -13,22 +15,8 @@
13
15
 
14
16
  <!-- For all browsers -->
15
17
  <link rel="stylesheet" href="{{ '/assets/css/main.css' | relative_url }}">
16
- <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@5/css/all.min.css">
17
-
18
- <!--[if IE]>
19
- <style>
20
- /* old IE unsupported flexbox fixes */
21
- .greedy-nav .site-title {
22
- padding-right: 3em;
23
- }
24
- .greedy-nav button {
25
- position: absolute;
26
- top: 0;
27
- right: 0;
28
- height: 100%;
29
- }
30
- </style>
31
- <![endif]-->
18
+ <link rel="preload" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@5/css/all.min.css" as="style" onload="this.onload=null;this.rel='stylesheet'">
19
+ <noscript><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@5/css/all.min.css"></noscript>
32
20
 
33
21
  {% if site.head_scripts %}
34
22
  {% for script in site.head_scripts %}
@@ -5,7 +5,7 @@
5
5
  <div class="masthead__menu">
6
6
  <nav id="site-nav" class="greedy-nav">
7
7
  {% unless logo_path == empty %}
8
- <a class="site-logo" href="{{ '/' | relative_url }}"><img src="{{ logo_path | relative_url }}" alt=""></a>
8
+ <a class="site-logo" href="{{ '/' | relative_url }}"><img src="{{ logo_path | relative_url }}" alt="{{ site.masthead_title | default: site.title }}"></a>
9
9
  {% endunless %}
10
10
  <a class="site-title" href="{{ '/' | relative_url }}">
11
11
  {{ site.masthead_title | default: site.title }}
@@ -21,9 +21,7 @@
21
21
  {% if site.search == true %}
22
22
  <button class="search__toggle" type="button">
23
23
  <span class="visually-hidden">{{ site.data.ui-text[site.locale].search_label | default: "Toggle search" }}</span>
24
- <svg class="icon" width="16" height="16" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 15.99 16">
25
- <path d="M15.5,13.12L13.19,10.8a1.69,1.69,0,0,0-1.28-.55l-0.06-.06A6.5,6.5,0,0,0,5.77,0,6.5,6.5,0,0,0,2.46,11.59a6.47,6.47,0,0,0,7.74.26l0.05,0.05a1.65,1.65,0,0,0,.5,1.24l2.38,2.38A1.68,1.68,0,0,0,15.5,13.12ZM6.4,2A4.41,4.41,0,1,1,2,6.4,4.43,4.43,0,0,1,6.4,2Z" transform="translate(-.01)"></path>
26
- </svg>
24
+ <i class="fas fa-search"></i>
27
25
  </button>
28
26
  {% endif %}
29
27
  <button class="greedy-nav__toggle hidden" type="button">
@@ -1,5 +1,6 @@
1
+ {% assign date_format = site.date_format | default: "%B %-d, %Y" %}
1
2
  {% if page.last_modified_at %}
2
- <p class="page__date"><strong><i class="fas fa-fw fa-calendar-alt" aria-hidden="true"></i> {{ site.data.ui-text[site.locale].date_label | default: "Updated:" }}</strong> <time datetime="{{ page.last_modified_at | date: "%Y-%m-%d" }}">{{ page.last_modified_at | date: "%B %-d, %Y" }}</time></p>
3
+ <p class="page__date"><strong><i class="fas fa-fw fa-calendar-alt" aria-hidden="true"></i> {{ site.data.ui-text[site.locale].date_label | default: "Updated:" }}</strong> <time datetime="{{ page.last_modified_at | date: "%Y-%m-%d" }}">{{ page.last_modified_at | date: date_format }}</time></p>
3
4
  {% elsif page.date %}
4
- <p class="page__date"><strong><i class="fas fa-fw fa-calendar-alt" aria-hidden="true"></i> {{ site.data.ui-text[site.locale].date_label | default: "Updated:" }}</strong> <time datetime="{{ page.date | date_to_xmlschema }}">{{ page.date | date: "%B %-d, %Y" }}</time></p>
5
+ <p class="page__date"><strong><i class="fas fa-fw fa-calendar-alt" aria-hidden="true"></i> {{ site.data.ui-text[site.locale].date_label | default: "Updated:" }}</strong> <time datetime="{{ page.date | date_to_xmlschema }}">{{ page.date | date: date_format }}</time></p>
5
6
  {% endif %}
@@ -1,9 +1,13 @@
1
1
  {% capture overlay_img_path %}{{ page.header.overlay_image | relative_url }}{% endcapture %}
2
2
 
3
- {% if page.header.overlay_filter contains "rgba" %}
3
+ {% if page.header.overlay_filter contains "gradient" %}
4
4
  {% capture overlay_filter %}{{ page.header.overlay_filter }}{% endcapture %}
5
+ {% elsif page.header.overlay_filter contains "rgba" %}
6
+ {% capture overlay_filter %}{{ page.header.overlay_filter }}{% endcapture %}
7
+ {% capture overlay_filter %}linear-gradient({{ overlay_filter }}, {{ overlay_filter }}){% endcapture %}
5
8
  {% elsif page.header.overlay_filter %}
6
9
  {% capture overlay_filter %}rgba(0, 0, 0, {{ page.header.overlay_filter }}){% endcapture %}
10
+ {% capture overlay_filter %}linear-gradient({{ overlay_filter }}, {{ overlay_filter }}){% endcapture %}
7
11
  {% endif %}
8
12
 
9
13
  {% if page.header.image_description %}
@@ -15,7 +19,7 @@
15
19
  {% assign image_description = image_description | markdownify | strip_html | strip_newlines | escape_once %}
16
20
 
17
21
  <div class="page__hero{% if page.header.overlay_color or page.header.overlay_image %}--overlay{% endif %}"
18
- style="{% if page.header.overlay_color %}background-color: {{ page.header.overlay_color | default: 'transparent' }};{% endif %} {% if overlay_img_path %}background-image: {% if overlay_filter %}linear-gradient({{ overlay_filter }}, {{ overlay_filter }}), {% endif %}url('{{ overlay_img_path }}');{% endif %}"
22
+ style="{% if page.header.overlay_color %}background-color: {{ page.header.overlay_color | default: 'transparent' }};{% endif %} {% if overlay_img_path %}background-image: {% if overlay_filter %}{{ overlay_filter }}, {% endif %}url('{{ overlay_img_path }}');{% endif %}"
19
23
  >
20
24
  {% if page.header.overlay_color or page.header.overlay_image %}
21
25
  <div class="wrapper">
@@ -31,7 +35,7 @@
31
35
  {% elsif page.header.show_overlay_excerpt != false and page.excerpt %}
32
36
  <p class="page__lead">{{ page.excerpt | markdownify | remove: "<p>" | remove: "</p>" }}</p>
33
37
  {% endif %}
34
- {% include post__meta.html %}
38
+ {% include page__meta.html %}
35
39
  {% if page.header.cta_url %}
36
40
  <p><a href="{{ page.header.cta_url | relative_url }}" class="btn btn--light-outline btn--large">{{ page.header.cta_label | default: site.data.ui-text[site.locale].more_label | default: "Learn More" }}</a></p>
37
41
  {% endif %}
@@ -0,0 +1,31 @@
1
+ {% assign document = post | default: page %}
2
+ {% if document.read_time or document.show_date %}
3
+ <p class="page__meta">
4
+ {% if document.show_date and document.date %}
5
+ {% assign date = document.date %}
6
+ <span class="page__meta-date">
7
+ <i class="far {% if include.type == 'grid' and document.read_time and document.show_date %}fa-fw {% endif %}fa-calendar-alt" aria-hidden="true"></i>
8
+ {% assign date_format = site.date_format | default: "%B %-d, %Y" %}
9
+ <time datetime="{{ date | date_to_xmlschema }}">{{ date | date: date_format }}</time>
10
+ </span>
11
+ {% endif %}
12
+
13
+ {% if document.read_time and document.show_date %}<span class="page__meta-sep"></span>{% endif %}
14
+
15
+ {% if document.read_time %}
16
+ {% assign words_per_minute = document.words_per_minute | default: site.words_per_minute | default: 200 %}
17
+ {% assign words = document.content | strip_html | number_of_words %}
18
+
19
+ <span class="page__meta-readtime">
20
+ <i class="far {% if include.type == 'grid' and document.read_time and document.show_date %}fa-fw {% endif %}fa-clock" aria-hidden="true"></i>
21
+ {% if words < words_per_minute %}
22
+ {{ site.data.ui-text[site.locale].less_than | default: "less than" }} 1 {{ site.data.ui-text[site.locale].minute_read | default: "minute read" }}
23
+ {% elsif words == words_per_minute %}
24
+ 1 {{ site.data.ui-text[site.locale].minute_read | default: "minute read" }}
25
+ {% else %}
26
+ {{ words | divided_by: words_per_minute }} {{ site.data.ui-text[site.locale].minute_read | default: "minute read" }}
27
+ {% endif %}
28
+ </span>
29
+ {% endif %}
30
+ </p>
31
+ {% endif %}
data/_includes/seo.html CHANGED
@@ -52,6 +52,9 @@
52
52
 
53
53
  {% if author.name %}
54
54
  <meta name="author" content="{{ author.name | default: author }}">
55
+ {% if og_type == "article" %}
56
+ <meta property="article:author" content="{{ author.name | default: author }}">
57
+ {% endif %}
55
58
  {% endif %}
56
59
 
57
60
  <meta property="og:type" content="{{ og_type }}">
@@ -149,4 +152,7 @@
149
152
  {% if site.naver_site_verification %}
150
153
  <meta name="naver-site-verification" content="{{ site.naver_site_verification }}">
151
154
  {% endif %}
155
+ {% if site.baidu_site_verification %}
156
+ <meta name="baidu-site-verification" content="{{ site.baidu_site_verification }}">
157
+ {% endif %}
152
158
  <!-- end _includes/seo.html -->
@@ -1,5 +1,4 @@
1
1
  <nav class="skip-links">
2
- <h2 class="screen-reader-text">{{ site.data.ui-text[site.locale].skip_links | default: 'Skip links' }}</h2>
3
2
  <ul>
4
3
  <li><a href="#site-nav" class="screen-reader-shortcut">{{ site.data.ui-text[site.locale].skip_primary_nav | default: 'Skip to primary navigation' }}</a></li>
5
4
  <li><a href="#main" class="screen-reader-shortcut">{{ site.data.ui-text[site.locale].skip_content | default: 'Skip to content' }}</a></li>
@@ -6,19 +6,12 @@
6
6
  {% endcase %}
7
7
 
8
8
  {% if site.tag_archive.path %}
9
- {% comment %}
10
- <!-- Sort alphabetically regardless of case e.g. a B c d E -->
11
- <!-- modified from http://www.codeofclimber.ru/2015/sorting-site-tags-in-jekyll/ -->
12
- {% endcomment %}
13
- {% capture page_tags %}{% for tag in page.tags %}{{ tag | downcase }}|{{ tag }}{% unless forloop.last %},{% endunless %}{% endfor %}{% endcapture %}
14
- {% assign tag_hashes = page_tags | split: ',' | sort %}
9
+ {% assign tags_sorted = page.tags | sort_natural %}
15
10
 
16
11
  <p class="page__taxonomy">
17
12
  <strong><i class="fas fa-fw fa-tags" aria-hidden="true"></i> {{ site.data.ui-text[site.locale].tags_label | default: "Tags:" }} </strong>
18
13
  <span itemprop="keywords">
19
- {% for hash in tag_hashes %}
20
- {% assign keyValue = hash | split: '|' %}
21
- {% capture tag_word %}{{ keyValue[1] | strip_newlines }}{% endcapture %}
14
+ {% for tag_word in tags_sorted %}
22
15
  <a href="{{ tag_word | slugify | prepend: path_type | prepend: site.tag_archive.path | relative_url }}" class="page__taxonomy-item" rel="tag">{{ tag_word }}</a>{% unless forloop.last %}<span class="sep">, </span>{% endunless %}
23
16
  {% endfor %}
24
17
  </span>
data/_includes/toc.html CHANGED
@@ -1,6 +1,30 @@
1
1
  {% capture tocWorkspace %}
2
2
  {% comment %}
3
- Version 1.0.8
3
+ Copyright (c) 2017 Vladimir "allejo" Jimenez
4
+
5
+ Permission is hereby granted, free of charge, to any person
6
+ obtaining a copy of this software and associated documentation
7
+ files (the "Software"), to deal in the Software without
8
+ restriction, including without limitation the rights to use,
9
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the
11
+ Software is furnished to do so, subject to the following
12
+ conditions:
13
+
14
+ The above copyright notice and this permission notice shall be
15
+ included in all copies or substantial portions of the Software.
16
+
17
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
19
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
21
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
22
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24
+ OTHER DEALINGS IN THE SOFTWARE.
25
+ {% endcomment %}
26
+ {% comment %}
27
+ Version 1.1.0
4
28
  https://github.com/allejo/jekyll-toc
5
29
 
6
30
  "...like all things liquid - where there's a will, and ~36 hours to spare, there's usually a/some way" ~jaybe
@@ -12,85 +36,147 @@
12
36
  * html (string) - the HTML of compiled markdown generated by kramdown in Jekyll
13
37
 
14
38
  Optional Parameters:
15
- * sanitize (bool) : false - when set to true, the headers will be stripped of any HTML in the TOC
16
- * class (string) : '' - a CSS class assigned to the TOC
17
- * id (string) : '' - an ID to assigned to the TOC
18
- * h_min (int) : 1 - the minimum TOC header level to use; any header lower than this value will be ignored
19
- * h_max (int) : 6 - the maximum TOC header level to use; any header greater than this value will be ignored
20
- * ordered (bool) : false - when set to true, an ordered list will be outputted instead of an unordered list
21
- * item_class (string) : '' - add custom class(es) for each list item; has support for '%level%' placeholder, which is the current heading level
22
- * baseurl (string) : '' - add a base url to the TOC links for when your TOC is on another page than the actual content
23
- * anchor_class (string) : '' - add custom class(es) for each anchor element
39
+ * sanitize (bool) : false - when set to true, the headers will be stripped of any HTML in the TOC
40
+ * class (string) : '' - a CSS class assigned to the TOC
41
+ * id (string) : '' - an ID to assigned to the TOC
42
+ * h_min (int) : 1 - the minimum TOC header level to use; any header lower than this value will be ignored
43
+ * h_max (int) : 6 - the maximum TOC header level to use; any header greater than this value will be ignored
44
+ * ordered (bool) : false - when set to true, an ordered list will be outputted instead of an unordered list
45
+ * item_class (string) : '' - add custom class(es) for each list item; has support for '%level%' placeholder, which is the current heading level
46
+ * submenu_class (string) : '' - add custom class(es) for each child group of headings; has support for '%level%' placeholder which is the current "submenu" heading level
47
+ * base_url (string) : '' - add a base url to the TOC links for when your TOC is on another page than the actual content
48
+ * anchor_class (string) : '' - add custom class(es) for each anchor element
49
+ * skip_no_ids (bool) : false - skip headers that do not have an `id` attribute
24
50
 
25
51
  Output:
26
52
  An ordered or unordered list representing the table of contents of a markdown block. This snippet will only
27
53
  generate the table of contents and will NOT output the markdown given to it
28
54
  {% endcomment %}
29
55
 
30
- {% capture my_toc %}{% endcapture %}
56
+ {% capture newline %}
57
+ {% endcapture %}
58
+ {% assign newline = newline | rstrip %} <!-- Remove the extra spacing but preserve the newline -->
59
+
60
+ {% capture deprecation_warnings %}{% endcapture %}
61
+
62
+ {% if include.baseurl %}
63
+ {% capture deprecation_warnings %}{{ deprecation_warnings }}<!-- jekyll-toc :: "baseurl" has been deprecated, use "base_url" instead -->{{ newline }}{% endcapture %}
64
+ {% endif %}
65
+
66
+ {% if include.skipNoIDs %}
67
+ {% capture deprecation_warnings %}{{ deprecation_warnings }}<!-- jekyll-toc :: "skipNoIDs" has been deprecated, use "skip_no_ids" instead -->{{ newline }}{% endcapture %}
68
+ {% endif %}
69
+
70
+ {% capture jekyll_toc %}{% endcapture %}
31
71
  {% assign orderedList = include.ordered | default: false %}
72
+ {% assign baseURL = include.base_url | default: include.baseurl | default: '' %}
73
+ {% assign skipNoIDs = include.skip_no_ids | default: include.skipNoIDs | default: false %}
32
74
  {% assign minHeader = include.h_min | default: 1 %}
33
75
  {% assign maxHeader = include.h_max | default: 6 %}
34
- {% assign nodes = include.html | split: '<h' %}
76
+ {% assign nodes = include.html | strip | split: '<h' %}
77
+
35
78
  {% assign firstHeader = true %}
79
+ {% assign currLevel = 0 %}
80
+ {% assign lastLevel = 0 %}
36
81
 
37
- {% capture listModifier %}{% if orderedList %}1.{% else %}-{% endif %}{% endcapture %}
82
+ {% capture listModifier %}{% if orderedList %}ol{% else %}ul{% endif %}{% endcapture %}
38
83
 
39
84
  {% for node in nodes %}
40
85
  {% if node == "" %}
41
86
  {% continue %}
42
87
  {% endif %}
43
88
 
44
- {% assign headerLevel = node | replace: '"', '' | slice: 0, 1 | times: 1 %}
89
+ {% assign currLevel = node | replace: '"', '' | slice: 0, 1 | times: 1 %}
45
90
 
46
- {% if headerLevel < minHeader or headerLevel > maxHeader %}
91
+ {% if currLevel < minHeader or currLevel > maxHeader %}
47
92
  {% continue %}
48
93
  {% endif %}
49
94
 
50
- {% if firstHeader %}
51
- {% assign firstHeader = false %}
52
- {% assign minHeader = headerLevel %}
53
- {% endif %}
54
-
55
- {% assign indentAmount = headerLevel | minus: minHeader %}
56
95
  {% assign _workspace = node | split: '</h' %}
57
96
 
58
97
  {% assign _idWorkspace = _workspace[0] | split: 'id="' %}
59
98
  {% assign _idWorkspace = _idWorkspace[1] | split: '"' %}
60
- {% assign html_id = _idWorkspace[0] %}
99
+ {% assign htmlID = _idWorkspace[0] %}
61
100
 
62
101
  {% assign _classWorkspace = _workspace[0] | split: 'class="' %}
63
102
  {% assign _classWorkspace = _classWorkspace[1] | split: '"' %}
64
- {% assign html_class = _classWorkspace[0] %}
103
+ {% assign htmlClass = _classWorkspace[0] %}
65
104
 
66
- {% if html_class contains "no_toc" %}
105
+ {% if htmlClass contains "no_toc" %}
67
106
  {% continue %}
68
107
  {% endif %}
69
108
 
109
+ {% if firstHeader %}
110
+ {% assign minHeader = currLevel %}
111
+ {% endif %}
112
+
70
113
  {% capture _hAttrToStrip %}{{ _workspace[0] | split: '>' | first }}>{% endcapture %}
71
114
  {% assign header = _workspace[0] | replace: _hAttrToStrip, '' %}
72
115
 
73
- {% assign space = '' %}
74
- {% for i in (1..indentAmount) %}
75
- {% assign space = space | prepend: ' ' %}
76
- {% endfor %}
116
+ {% if include.item_class and include.item_class != blank %}
117
+ {% capture listItemClass %} class="{{ include.item_class | replace: '%level%', currLevel | split: '.' | join: ' ' }}"{% endcapture %}
118
+ {% endif %}
119
+
120
+ {% if include.submenu_class and include.submenu_class != blank %}
121
+ {% assign subMenuLevel = currLevel | minus: 1 %}
122
+ {% capture subMenuClass %} class="{{ include.submenu_class | replace: '%level%', subMenuLevel | split: '.' | join: ' ' }}"{% endcapture %}
123
+ {% endif %}
77
124
 
78
- {% unless include.item_class == blank %}
79
- {% capture listItemClass %}{:.{{ include.item_class | replace: '%level%', headerLevel }}}{% endcapture %}
80
- {% endunless %}
125
+ {% capture anchorBody %}{% if include.sanitize %}{{ header | strip_html }}{% else %}{{ header }}{% endif %}{% endcapture %}
81
126
 
82
- {% capture heading_body %}{% if include.sanitize %}{{ header | strip_html }}{% else %}{{ header }}{% endif %}{% endcapture %}
83
- {% capture my_toc %}{{ my_toc }}
84
- {{ space }}{{ listModifier }} {{ listItemClass }} [{{ heading_body | replace: "|", "\|" }}]({% if include.baseurl %}{{ include.baseurl }}{% endif %}#{{ html_id }}){% if include.anchor_class %}{:.{{ include.anchor_class }}}{% endif %}{% endcapture %}
127
+ {% if htmlID %}
128
+ {% capture anchorAttributes %} href="{% if baseURL %}{{ baseURL }}{% endif %}#{{ htmlID }}"{% endcapture %}
129
+
130
+ {% if include.anchor_class %}
131
+ {% capture anchorAttributes %}{{ anchorAttributes }} class="{{ include.anchor_class | split: '.' | join: ' ' }}"{% endcapture %}
132
+ {% endif %}
133
+
134
+ {% capture listItem %}<a{{ anchorAttributes }}>{{ anchorBody }}</a>{% endcapture %}
135
+ {% elsif skipNoIDs == true %}
136
+ {% continue %}
137
+ {% else %}
138
+ {% capture listItem %}{{ anchorBody }}{% endcapture %}
139
+ {% endif %}
140
+
141
+ {% if currLevel > lastLevel %}
142
+ {% capture jekyll_toc %}{{ jekyll_toc }}<{{ listModifier }}{{ subMenuClass }}>{% endcapture %}
143
+ {% elsif currLevel < lastLevel %}
144
+ {% assign repeatCount = lastLevel | minus: currLevel %}
145
+
146
+ {% for i in (1..repeatCount) %}
147
+ {% capture jekyll_toc %}{{ jekyll_toc }}</li></{{ listModifier }}>{% endcapture %}
148
+ {% endfor %}
149
+
150
+ {% capture jekyll_toc %}{{ jekyll_toc }}</li>{% endcapture %}
151
+ {% else %}
152
+ {% capture jekyll_toc %}{{ jekyll_toc }}</li>{% endcapture %}
153
+ {% endif %}
154
+
155
+ {% capture jekyll_toc %}{{ jekyll_toc }}<li{{ listItemClass }}>{{ listItem }}{% endcapture %}
156
+
157
+ {% assign lastLevel = currLevel %}
158
+ {% assign firstHeader = false %}
85
159
  {% endfor %}
86
160
 
87
- {% if include.class %}
88
- {% capture my_toc %}{:.{{ include.class }}}
89
- {{ my_toc | lstrip }}{% endcapture %}
90
- {% endif %}
161
+ {% assign repeatCount = minHeader | minus: 1 %}
162
+ {% assign repeatCount = lastLevel | minus: repeatCount %}
163
+ {% for i in (1..repeatCount) %}
164
+ {% capture jekyll_toc %}{{ jekyll_toc }}</li></{{ listModifier }}>{% endcapture %}
165
+ {% endfor %}
166
+
167
+ {% if jekyll_toc != '' %}
168
+ {% assign rootAttributes = '' %}
169
+ {% if include.class and include.class != blank %}
170
+ {% capture rootAttributes %} class="{{ include.class | split: '.' | join: ' ' }}"{% endcapture %}
171
+ {% endif %}
172
+
173
+ {% if include.id and include.id != blank %}
174
+ {% capture rootAttributes %}{{ rootAttributes }} id="{{ include.id }}"{% endcapture %}
175
+ {% endif %}
91
176
 
92
- {% if include.id %}
93
- {% capture my_toc %}{: #{{ include.id }}}
94
- {{ my_toc | lstrip }}{% endcapture %}
177
+ {% if rootAttributes %}
178
+ {% assign nodes = jekyll_toc | split: '>' %}
179
+ {% capture jekyll_toc %}<{{ listModifier }}{{ rootAttributes }}>{{ nodes | shift | join: '>' }}>{% endcapture %}
180
+ {% endif %}
95
181
  {% endif %}
96
- {% endcapture %}{% assign tocWorkspace = '' %}{{ my_toc | markdownify | strip }}
182
+ {% endcapture %}{% assign tocWorkspace = '' %}{{ deprecation_warnings }}{{ jekyll_toc }}