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
This commit is contained in:
沈唁 2020-06-07 16:37:28 +08:00 committed by GitHub
parent 60263578ba
commit 31010e4979
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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