Skip to content

Commit

Permalink
website: fix search data error. #105 #32
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed Nov 17, 2022
1 parent 7479c10 commit 764b550
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
18 changes: 12 additions & 6 deletions scripts/create.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,18 @@ export function create(str = '', options = {}) {
if (!options.isHome) {
const tocsMenus = getTocsTitleNode([...tocsData]);
node.children = addTocsInWarp([...tocsData], getTocsTitleNodeWarpper(tocsMenus));
tocsMenus.forEach((menu) => {
detailData.sections.push({
a: menu?.properties?.href,
t: getCodeString(menu.children),
l: menu?.properties['data-num'],
});
tocsMenus.forEach((menu, idx) => {
const level = menu?.properties['data-num'];
if (idx + 1 === tocsMenus.length && level === 2) {
return;
}
if (level < 4) {
detailData.sections.push({
a: menu?.properties?.href,
t: getCodeString(menu.children),
l: menu?.properties['data-num'],
});
}
});
} else {
node.children = tocsData;
Expand Down
4 changes: 3 additions & 1 deletion scripts/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ export async function createHTML(files = [], num = 0) {
searchData[options.filename] = data;
searchData.name = options.filename;
await fs.writeJSON(SEARCH_DATA_CACHE, searchData);
const resultSearchData = Object.keys({ ...searchData }).map((name) => searchData[name]);
const resultSearchData = Object.keys({ ...searchData })
.map((name) => searchData[name])
.filter((item) => typeof item !== 'string');
await fs.writeJSON(SEARCH_DATA, resultSearchData);
}
await fs.writeFile(outputHTMLPath, html);
Expand Down

0 comments on commit 764b550

Please sign in to comment.