From 31010e4979b3d3ab4bd247a09c4ac5fd1405eaa8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B2=88=E5=94=81?= <52o@qq52o.cn> Date: Sun, 7 Jun 2020 16:37:28 +0800 Subject: [PATCH] fix: search does not find the contents of the table (#1198) * fix: search does not find the contents of the table * refactor: add getTableData function --- src/plugins/search/search.js | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/plugins/search/search.js b/src/plugins/search/search.js index 40e70bae..1c7c7789 100644 --- a/src/plugins/search/search.js +++ b/src/plugins/search/search.js @@ -54,6 +54,17 @@ function getAllPaths(router) { return paths; } +function getTableData(token) { + if (!token.text && token.type === 'table') { + token.text = token.cells + .map(function(rows) { + return rows.join(' | '); + }) + .join(' |\n '); + } + return token.text; +} + function saveData(maxAge, expireKey, indexKey) { localStorage.setItem(expireKey, Date.now() + maxAge); localStorage.setItem(indexKey, JSON.stringify(INDEXS)); @@ -84,17 +95,11 @@ export function genIndex(path, content = '', router, depth) { if (!index[slug]) { index[slug] = { slug, title: '', body: '' }; } else if (index[slug].body) { + token.text = getTableData(token); + index[slug].body += '\n' + (token.text || ''); } else { - if (!token.text) { - if (token.type === 'table') { - token.text = token.cells - .map(function(rows) { - return rows.join(' | '); - }) - .join(' |\n '); - } - } + token.text = getTableData(token); index[slug].body = index[slug].body ? index[slug].body + token.text