Skip to content

Commit 398a113

Browse files
committed
Improved the TOC.
Automatically hide TOC titles
1 parent 53ad698 commit 398a113

3 files changed

Lines changed: 16 additions & 1 deletion

File tree

_layouts/post.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,13 @@ <h1 data-toc-skip>{{ page.title }}</h1>
100100
{% if site.toc and page.toc %}
101101
<div id="toc-wrap" class="topbar-down pr-4">
102102
<h3 data-toc-skip class="pl-3 pt-2">
103-
{{ site.data.label.panel.toc }}
103+
{{- site.data.label.panel.toc -}}
104104
</h3>
105105
<nav id="toc" data-toggle="toc"></nav>
106106
</div>
107107
<link rel="stylesheet" href="{{ site.baseurl }}/assets/lib/bootstrap-toc-1.0.1/bootstrap-toc.min.css" />
108108
<script src="{{ site.baseurl }}/assets/lib/bootstrap-toc-1.0.1/bootstrap-toc.min.js"></script>
109+
<script src="{{ site.baseurl }}/assets/js/dist/toc.min.js"></script>
109110
{% endif %}
110111
</div> <!-- #post-panel -->
111112

assets/js/_src/toc.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/*
2+
* Hide the empty ToC in posts.
3+
*
4+
* © 2019 Cotes Chung
5+
* MIT Licensed
6+
*/
7+
8+
$(function() {
9+
// Hide ToC title if there is no head
10+
if ($("#toc-wrap>nav#toc>ul>li").length == 0) {
11+
$("#toc-wrap>h3").addClass("hidden");
12+
}
13+
});

assets/js/dist/toc.min.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
$(function(){if($("#toc-wrap>nav#toc>ul>li").length==0){$("#toc-wrap>h3").addClass("hidden")}});

0 commit comments

Comments
 (0)