website: fix search data error. #105 #32

This commit is contained in:
jaywcjlove 2022-11-17 17:08:26 +08:00
parent 7479c1045c
commit 764b55045d
2 changed files with 15 additions and 7 deletions

View File

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

View File

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