Commit 8483e8ac by Lin Wang

fix: add the category field

parent d78ba114
...@@ -31,7 +31,7 @@ const baselinePath = join(srcDir, baselineFile); ...@@ -31,7 +31,7 @@ const baselinePath = join(srcDir, baselineFile);
const baselineData = JSON.parse(readFileSync(baselinePath, 'utf-8')); const baselineData = JSON.parse(readFileSync(baselinePath, 'utf-8'));
// Fields to ignore during diff // Fields to ignore during diff
const ignoreFields = ['pageUid', 'pageTitle', 'id', 'path']; const ignoreFields = ['category', 'pageUid', 'pageTitle', 'id', 'path'];
selectedSelectors selectedSelectors
.filter(id => Number(id) !== baselineId) .filter(id => Number(id) !== baselineId)
...@@ -53,6 +53,8 @@ selectedSelectors ...@@ -53,6 +53,8 @@ selectedSelectors
const langA = selectedLanguages[baselineId]; const langA = selectedLanguages[baselineId];
const langB = selectedLanguages[otherId]; const langB = selectedLanguages[otherId];
// pageUid, pageTitle, sectionIndex // pageUid, pageTitle, sectionIndex
context[`${langA}:category`] = pageA.category;
context[`${langB}:category`] = pageB.category;
context[`${langA}:subcategory`] = pageA.pageTitle; context[`${langA}:subcategory`] = pageA.pageTitle;
context[`${langB}:subcategory`] = pageB.pageTitle; context[`${langB}:subcategory`] = pageB.pageTitle;
context[`${langA}:sectionIndex`] = pageA.sectionIndex; context[`${langA}:sectionIndex`] = pageA.sectionIndex;
......
...@@ -546,17 +546,25 @@ export function mainParse(jsonData) { ...@@ -546,17 +546,25 @@ export function mainParse(jsonData) {
// 生成导航信息 // 生成导航信息
const navigationInfo = getNavigationInfo(jsonData.navigation.items); const navigationInfo = getNavigationInfo(jsonData.navigation.items);
// 遍历 pages 数组
const navLinks = jsonData.navigation.items.reduce((pre, cur) => { const navLinks = jsonData.navigation.items.reduce((pre, cur) => {
if (cur.items) { 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; return pre;
}, []); }, []);
const pages = navLinks.map((item) => { // 遍历 pages 数组,并将 category 合并到 page 对象中
return jsonData.pages.find((page) => page.uid === item.id); 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)) { if (Array.isArray(pages)) {
pages.forEach((page, pageIndex) => { pages.forEach((page, pageIndex) => {
...@@ -572,6 +580,7 @@ export function mainParse(jsonData) { ...@@ -572,6 +580,7 @@ export function mainParse(jsonData) {
result.push({ result.push({
pageIndex, pageIndex,
pageUid: page.uid, pageUid: page.uid,
category: page.category || '无 category',
pageTitle: page.title, pageTitle: page.title,
sectionIndex: sectionIndex, sectionIndex: sectionIndex,
result: sectionResult.result, 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