Skip to content

Commit d0ecc42

Browse files
committed
refactor: add getTableData function
1 parent 6ed4bb1 commit d0ecc42

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

src/plugins/search/search.js

+13-14
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,23 +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) {
87-
if (!token.text && token.type === 'table') {
88-
token.text = token.cells
89-
.map(function(rows) {
90-
return rows.join(' | ');
91-
})
92-
.join(' |\n ');
93-
}
98+
token.text = getTableData(token);
9499

95100
index[slug].body += '\n' + (token.text || '');
96101
} else {
97-
if (!token.text && token.type === 'table') {
98-
token.text = token.cells
99-
.map(function(rows) {
100-
return rows.join(' | ');
101-
})
102-
.join(' |\n ');
103-
}
102+
token.text = getTableData(token);
104103

105104
index[slug].body = index[slug].body
106105
? index[slug].body + token.text

0 commit comments

Comments
 (0)