Skip to content

Commit

Permalink
fix: search does not find the contents of the table (#1198)
Browse files Browse the repository at this point in the history
* fix: search does not find the contents of the table

* refactor: add getTableData function
  • Loading branch information
sy-records committed Jun 7, 2020
1 parent 6026357 commit 31010e4
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions src/plugins/search/search.js
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

1 comment on commit 31010e4

@vercel
Copy link

@vercel vercel bot commented on 31010e4 Jun 7, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.