From 81f6d7136a58662137495ca415c520968432c13b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E6=B6=9B?= Date: Thu, 15 Sep 2022 17:57:43 +0800 Subject: [PATCH] Update toc.js fix: In search plugin, after type keyword and jump to result page, the search results are shown in toc. --- src/toc.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/toc.js b/src/toc.js index e48d633..cda170a 100644 --- a/src/toc.js +++ b/src/toc.js @@ -2,7 +2,7 @@ function pageToC (headings, path) { let toc = ['
'] const list = [] - headings = document.querySelectorAll(`#main ${window.$docsify.toc.target}`) + headings = findTitles() if (headings) { headings.forEach(function (heading) { @@ -33,7 +33,7 @@ function generateToC (level, html) { // scroll listener const scrollHandler = () => { const clientHeight = window.innerHeight - const titleBlocks = document.querySelectorAll(`#main ${window.$docsify.toc.target}`) + const titleBlocks = findTitles() let insightBlocks = [] titleBlocks.forEach((titleBlock, index) => { const rect = titleBlock.getBoundingClientRect() @@ -62,6 +62,14 @@ const scrollHandler = () => { }) } } +// find toc titles +function findTitles() { + const targets = window.$docsify.toc.target.split(',') + const selectors = targets.map(item => { + return `#main ${item}` + }).join(',') + return document.querySelectorAll(selectors) +} export function install (hook, vm) { hook.mounted(function () {