From ba79f07cbae62be259b1d1eb20dad8abe7c8d998 Mon Sep 17 00:00:00 2001 From: "Kenneth G. Franqueiro" Date: Fri, 26 Sep 2025 13:15:13 -0400 Subject: [PATCH] Deduplicate entries under "This technique relates to" --- 11ty/techniques.ts | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/11ty/techniques.ts b/11ty/techniques.ts index 47119c1255..25c7b43f63 100644 --- a/11ty/techniques.ts +++ b/11ty/techniques.ts @@ -272,10 +272,28 @@ export async function getTechniqueAssociations( } // Remove duplicates (due to similar shape across understanding docs) and sort by SC number - for (const [key, list] of Object.entries(associations)) - associations[key] = uniqBy(list, (v) => JSON.stringify(v)).sort((a, b) => + for (const [key, list] of Object.entries(associations)) { + const deduplicatedList = uniqBy(list, (v) => JSON.stringify(v)).sort((a, b) => wcagSort(a.criterion, b.criterion) ); + // Remove entries that are redundant of a more generalized preceding entry + for (let i = 1; i < deduplicatedList.length; i++) { + const previousEntry = deduplicatedList[i - 1]; + const entry = deduplicatedList[i]; + if ( + entry.criterion.id === previousEntry.criterion.id && + entry.type === previousEntry.type && + !previousEntry.hasUsageChildren && + !previousEntry.usageParentDescription && + !previousEntry.usageParentIds.length && + !previousEntry.with.length + ) { + deduplicatedList.splice(i, 1); + i--; // Next item is now in this index; repeat processing it + } + } + associations[key] = deduplicatedList; + } return associations; }