From 8225174cb5e02fda7b3cc548ec821c876b0a5139 Mon Sep 17 00:00:00 2001 From: Cotes Chung <11371340+cotes2020@users.noreply.github.com> Date: Fri, 31 Mar 2023 05:05:33 +0800 Subject: [PATCH] fix(deps): `tocbot` has no initialization detection (#957) Resolves #957 --- _javascript/modules/components/toc.js | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/_javascript/modules/components/toc.js b/_javascript/modules/components/toc.js index ba0415d3ff8..dd46994e97d 100644 --- a/_javascript/modules/components/toc.js +++ b/_javascript/modules/components/toc.js @@ -1,11 +1,13 @@ export function toc() { - // see: https://github.com/tscanlin/tocbot#usage - tocbot.init({ - tocSelector: '#toc', - contentSelector: '.post-content', - ignoreSelector: '[data-toc-skip]', - headingSelector: 'h2, h3', - orderedList: false, - scrollSmooth: false - }); + if (document.querySelector('#core-wrapper h2,#core-wrapper h3')) { + // see: https://github.com/tscanlin/tocbot#usage + tocbot.init({ + tocSelector: '#toc', + contentSelector: '.post-content', + ignoreSelector: '[data-toc-skip]', + headingSelector: 'h2, h3', + orderedList: false, + scrollSmooth: false + }); + } }