Improved the TOC.

Automatically hide TOC titles
This commit is contained in:
Cotes Chung 2019-10-08 19:58:17 +08:00
parent a76e41a5dc
commit cf4a7f2e2f
3 changed files with 16 additions and 1 deletions

View file

@ -100,12 +100,13 @@ layout: default
{% if site.toc and page.toc %} {% if site.toc and page.toc %}
<div id="toc-wrap" class="topbar-down pr-4"> <div id="toc-wrap" class="topbar-down pr-4">
<h3 data-toc-skip class="pl-3 pt-2"> <h3 data-toc-skip class="pl-3 pt-2">
{{ site.data.label.panel.toc }} {{- site.data.label.panel.toc -}}
</h3> </h3>
<nav id="toc" data-toggle="toc"></nav> <nav id="toc" data-toggle="toc"></nav>
</div> </div>
<link rel="stylesheet" href="{{ site.baseurl }}/assets/lib/bootstrap-toc-1.0.1/bootstrap-toc.min.css" /> <link rel="stylesheet" href="{{ site.baseurl }}/assets/lib/bootstrap-toc-1.0.1/bootstrap-toc.min.css" />
<script src="{{ site.baseurl }}/assets/lib/bootstrap-toc-1.0.1/bootstrap-toc.min.js"></script> <script src="{{ site.baseurl }}/assets/lib/bootstrap-toc-1.0.1/bootstrap-toc.min.js"></script>
<script src="{{ site.baseurl }}/assets/js/dist/toc.min.js"></script>
{% endif %} {% endif %}
</div> <!-- #post-panel --> </div> <!-- #post-panel -->

13
assets/js/_src/toc.js Normal file
View file

@ -0,0 +1,13 @@
/*
* Hide the empty ToC in posts.
*
* © 2019 Cotes Chung
* MIT Licensed
*/
$(function() {
// Hide ToC title if there is no head
if ($("#toc-wrap>nav#toc>ul>li").length == 0) {
$("#toc-wrap>h3").addClass("hidden");
}
});

1
assets/js/dist/toc.min.js vendored Normal file
View file

@ -0,0 +1 @@
$(function(){if($("#toc-wrap>nav#toc>ul>li").length==0){$("#toc-wrap>h3").addClass("hidden")}});