Commit 8483e8ac by Lin Wang

fix: add the category field

parent d78ba114
......@@ -31,7 +31,7 @@ const baselinePath = join(srcDir, baselineFile);
const baselineData = JSON.parse(readFileSync(baselinePath, 'utf-8'));
// Fields to ignore during diff
const ignoreFields = ['pageUid', 'pageTitle', 'id', 'path'];
const ignoreFields = ['category', 'pageUid', 'pageTitle', 'id', 'path'];
selectedSelectors
.filter(id => Number(id) !== baselineId)
......@@ -53,6 +53,8 @@ selectedSelectors
const langA = selectedLanguages[baselineId];
const langB = selectedLanguages[otherId];
// pageUid, pageTitle, sectionIndex
context[`${langA}:category`] = pageA.category;
context[`${langB}:category`] = pageB.category;
context[`${langA}:subcategory`] = pageA.pageTitle;
context[`${langB}:subcategory`] = pageB.pageTitle;
context[`${langA}:sectionIndex`] = pageA.sectionIndex;
......
......@@ -546,17 +546,25 @@ export function mainParse(jsonData) {
// 生成导航信息
const navigationInfo = getNavigationInfo(jsonData.navigation.items);
// 遍历 pages 数组
const navLinks = jsonData.navigation.items.reduce((pre, cur) => {
if (cur.items) {
return pre.concat(cur.items);
// merge cur.title into each child item
return pre.concat(
cur.items.map(item => ({
...item,
category: cur.title,
}))
);
}
return pre;
}, []);
const pages = navLinks.map((item) => {
return jsonData.pages.find((page) => page.uid === item.id);
});
// 遍历 pages 数组,并将 category 合并到 page 对象中
const pages = navLinks.flatMap((item) => {
const page = jsonData.pages.find((page) => page.uid === item.id);
// 如果找到对应页面,则附加 category 字段并返回,否则跳过
return page ? [{ ...page, category: item.category }] : [];
})
if (Array.isArray(pages)) {
pages.forEach((page, pageIndex) => {
......@@ -572,6 +580,7 @@ export function mainParse(jsonData) {
result.push({
pageIndex,
pageUid: page.uid,
category: page.category || '无 category',
pageTitle: page.title,
sectionIndex: sectionIndex,
result: sectionResult.result,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment