Skip to content

Commit 31010e4

Browse files
authored
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
1 parent 6026357 commit 31010e4

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

src/plugins/search/search.js

+14-9
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,17 @@ function getAllPaths(router) {
5454
return paths;
5555
}
5656

57+
function getTableData(token) {
58+
if (!token.text && token.type === 'table') {
59+
token.text = token.cells
60+
.map(function(rows) {
61+
return rows.join(' | ');
62+
})
63+
.join(' |\n ');
64+
}
65+
return token.text;
66+
}
67+
5768
function saveData(maxAge, expireKey, indexKey) {
5869
localStorage.setItem(expireKey, Date.now() + maxAge);
5970
localStorage.setItem(indexKey, JSON.stringify(INDEXS));
@@ -84,17 +95,11 @@ export function genIndex(path, content = '', router, depth) {
8495
if (!index[slug]) {
8596
index[slug] = { slug, title: '', body: '' };
8697
} else if (index[slug].body) {
98+
token.text = getTableData(token);
99+
87100
index[slug].body += '\n' + (token.text || '');
88101
} else {
89-
if (!token.text) {
90-
if (token.type === 'table') {
91-
token.text = token.cells
92-
.map(function(rows) {
93-
return rows.join(' | ');
94-
})
95-
.join(' |\n ');
96-
}
97-
}
102+
token.text = getTableData(token);
98103

99104
index[slug].body = index[slug].body
100105
? index[slug].body + token.text

0 commit comments

Comments
 (0)