From cf4a7f2e2f763167fe088258eee7950b056167c0 Mon Sep 17 00:00:00 2001 From: Cotes Chung <11371340+cotes2020@users.noreply.github.com> Date: Tue, 8 Oct 2019 19:58:17 +0800 Subject: [PATCH] Improved the TOC. Automatically hide TOC titles --- _layouts/post.html | 3 ++- assets/js/_src/toc.js | 13 +++++++++++++ assets/js/dist/toc.min.js | 1 + 3 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 assets/js/_src/toc.js create mode 100644 assets/js/dist/toc.min.js diff --git a/_layouts/post.html b/_layouts/post.html index 83e4230..7398f4e 100644 --- a/_layouts/post.html +++ b/_layouts/post.html @@ -100,12 +100,13 @@ layout: default {% if site.toc and page.toc %}
+ {% endif %} diff --git a/assets/js/_src/toc.js b/assets/js/_src/toc.js new file mode 100644 index 0000000..513e99a --- /dev/null +++ b/assets/js/_src/toc.js @@ -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"); + } +}); \ No newline at end of file diff --git a/assets/js/dist/toc.min.js b/assets/js/dist/toc.min.js new file mode 100644 index 0000000..c158e79 --- /dev/null +++ b/assets/js/dist/toc.min.js @@ -0,0 +1 @@ +$(function(){if($("#toc-wrap>nav#toc>ul>li").length==0){$("#toc-wrap>h3").addClass("hidden")}}); \ No newline at end of file