Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: search does not find the contents of the table #1198

Merged
merged 2 commits into from
Jun 7, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions src/plugins/search/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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
Expand Down