Commit 61f9cd7d by Lin Wang

feat: increase the section count field

parent 1dd3947a
...@@ -24,7 +24,7 @@ const baselinePath = join(srcDir, baselineFile); ...@@ -24,7 +24,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 = ['category']; const ignoreFields = ['category', 'subcategory', 'id',];
// Get all nav files excluding baseline // Get all nav files excluding baseline
const allFiles = readdirSync(srcDir).filter(f => f.endsWith('_extractNav.json') && f !== baselineFile); const allFiles = readdirSync(srcDir).filter(f => f.endsWith('_extractNav.json') && f !== baselineFile);
...@@ -59,12 +59,24 @@ allFiles.forEach(file => { ...@@ -59,12 +59,24 @@ allFiles.forEach(file => {
// Include category context for troubleshooting // Include category context for troubleshooting
let categoryA: any = 'Not Applicable'; let categoryA: any = 'Not Applicable';
let categoryB: any = 'Not Applicable'; let categoryB: any = 'Not Applicable';
let subcategoryA: any = 'Not Applicable';
let subcategoryB: any = 'Not Applicable';
let idA: any = 'Not Applicable';
let idB: any = 'Not Applicable';
let typeA: any = 'Not Applicable';
let typeB: any = 'Not Applicable';
if (change.path && change.path[0] !== undefined && typeof change.path[0] === 'number') { if (change.path && change.path[0] !== undefined && typeof change.path[0] === 'number') {
const idx = change.path[0] as number; const idx = change.path[0] as number;
const entryA = baselineData[idx] || {}; const entryA = baselineData[idx] || {};
const entryB = otherData[idx] || {}; const entryB = otherData[idx] || {};
categoryA = entryA.category || 'Not Applicable'; categoryA = entryA.category || 'Not Applicable';
categoryB = entryB.category || 'Not Applicable'; categoryB = entryB.category || 'Not Applicable';
subcategoryA = entryA.subcategory || 'Not Applicable';
subcategoryB = entryB.subcategory || 'Not Applicable';
idA = entryA.id || 'Not Applicable';
idB = entryB.id || 'Not Applicable';
typeA = entryA.type || 'Not Applicable';
typeB = entryB.type || 'Not Applicable';
} }
return { return {
[`更改类型:${selectedLanguages[diffBaselineId]} vs ${selectedLanguages[otherId]}`]: type, [`更改类型:${selectedLanguages[diffBaselineId]} vs ${selectedLanguages[otherId]}`]: type,
...@@ -72,7 +84,13 @@ allFiles.forEach(file => { ...@@ -72,7 +84,13 @@ allFiles.forEach(file => {
[`模版值:${selectedLanguages[diffBaselineId]}`]: oldV || 'Not Applicable', [`模版值:${selectedLanguages[diffBaselineId]}`]: oldV || 'Not Applicable',
[`模版值:${selectedLanguages[otherId]}`]: newV || 'Not Applicable', [`模版值:${selectedLanguages[otherId]}`]: newV || 'Not Applicable',
[`category:${selectedLanguages[diffBaselineId]}`]: categoryA, [`category:${selectedLanguages[diffBaselineId]}`]: categoryA,
[`category:${selectedLanguages[otherId]}`]: categoryB [`category:${selectedLanguages[otherId]}`]: categoryB,
[`subcategory:${selectedLanguages[diffBaselineId]}`]: subcategoryA,
[`subcategory:${selectedLanguages[otherId]}`]: subcategoryB,
[`type:${selectedLanguages[diffBaselineId]}`]: typeA,
[`type:${selectedLanguages[otherId]}`]: typeB,
[`id:${selectedLanguages[diffBaselineId]}`]: idA,
[`id:${selectedLanguages[otherId]}`]: idB,
}; };
}); });
......
...@@ -544,7 +544,7 @@ export function mainParse(jsonData) { ...@@ -544,7 +544,7 @@ export function mainParse(jsonData) {
const themePreColors = jsonData.customColors?.themePreColors || []; const themePreColors = jsonData.customColors?.themePreColors || [];
const result = []; const result = [];
// 生成导航信息 // 生成导航信息
const navigationInfo = getNavigationInfo(jsonData.navigation.items); let navigationInfo = getNavigationInfo(jsonData.navigation.items);
const navLinks = jsonData.navigation.items.reduce((pre, cur) => { const navLinks = jsonData.navigation.items.reduce((pre, cur) => {
if (cur.items) { if (cur.items) {
...@@ -562,10 +562,18 @@ export function mainParse(jsonData) { ...@@ -562,10 +562,18 @@ export function mainParse(jsonData) {
// 遍历 pages 数组,并将 category 合并到 page 对象中 // 遍历 pages 数组,并将 category 合并到 page 对象中
const pages = navLinks.flatMap((item) => { const pages = navLinks.flatMap((item) => {
const page = jsonData.pages.find((page) => page.uid === item.id); const page = jsonData.pages.find((page) => page.uid === item.id);
// 如果找到对应页面,则附加 category 字段并返回,否则跳过
return page ? [{ ...page, category: item.category }] : []; return page ? [{ ...page, category: item.category }] : [];
}) })
// add sections count to navigationInfo based on pages
navigationInfo.forEach(entry => {
if (entry.type === 'page') {
const pageObj = pages.find(p => p.uid?.toString() === entry.id?.toString());
entry.subcategory = pageObj?.title || '';
entry.sections_count = pageObj?.sections?.length || 0;
}
});
if (Array.isArray(pages)) { if (Array.isArray(pages)) {
pages.forEach((page, pageIndex) => { pages.forEach((page, pageIndex) => {
// 遍历 sections 数组 // 遍历 sections 数组
......
...@@ -14,8 +14,8 @@ export const getNavigationInfo = (items, pathArr: string[] = []) => { ...@@ -14,8 +14,8 @@ export const getNavigationInfo = (items, pathArr: string[] = []) => {
navigationResult.push({ navigationResult.push({
patch: currentPathArr.join("."), patch: currentPathArr.join("."),
type: type, type: type,
category, id: item.id || null,
dropdown_count: itemsCount, ...(type === "dropdown" ? { dropdown_count: itemsCount, category } : {}),
}); });
// 递归处理 dropdown // 递归处理 dropdown
......
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