From c381353f86212cd11e555b320d3a1b82629b6c16 Mon Sep 17 00:00:00 2001 From: Cotes Chung <11371340+cotes2020@users.noreply.github.com> Date: Mon, 28 Dec 2020 00:14:10 +0800 Subject: [PATCH] Use liquid to determine whether to render ToC --- _includes/panel.html | 12 ++++++------ _layouts/post.html | 10 +++++++++- assets/js/_utils/toc-filter.js | 14 -------------- assets/js/post.min.js | 2 -- 4 files changed, 15 insertions(+), 23 deletions(-) delete mode 100644 assets/js/_utils/toc-filter.js diff --git a/_includes/panel.html b/_includes/panel.html index 767964d..ff17f45 100644 --- a/_includes/panel.html +++ b/_includes/panel.html @@ -47,13 +47,13 @@ {% endif %} - {% if page.layout == 'post' and site.toc and page.toc %} -
- + {% if include.toc %} +
+ {{- site.data.label.panel.toc -}} - - -
+
+ +
{% endif %} diff --git a/_layouts/post.html b/_layouts/post.html index faf2d3f..35f241a 100644 --- a/_layouts/post.html +++ b/_layouts/post.html @@ -111,7 +111,15 @@ layout: default - {% include panel.html %} + {% assign enable_toc = false %} + + {% if site.toc and page.toc %} + {% if content contains ' diff --git a/assets/js/_utils/toc-filter.js b/assets/js/_utils/toc-filter.js deleted file mode 100644 index 1c4f8f9..0000000 --- a/assets/js/_utils/toc-filter.js +++ /dev/null @@ -1,14 +0,0 @@ -/* - * Hide the empty ToC in posts. - * v2.0 - * https://github.com/cotes2020/jekyll-theme-chirpy - * © 2019 Cotes Chung - * MIT Licensed - */ - -$(function() { - if ($("#post-wrapper .post-content h1").length === 0 - && $("#post-wrapper .post-content h2").length === 0) { - $("#toc-wrapper").addClass("unloaded"); - } -}); \ No newline at end of file diff --git a/assets/js/post.min.js b/assets/js/post.min.js index c86d592..1536651 100644 --- a/assets/js/post.min.js +++ b/assets/js/post.min.js @@ -12,8 +12,6 @@ layout: compress {% include_relative lib/_bootstrap-toc.min.js %} -{% include_relative _utils/toc-filter.js %} - {% include_relative _utils/img-hyperlink.js %} {% include_relative _utils/lang-badge.js %}