Skip to content

Commit 5faa1ad

Browse files
kfranqueirombgower
andauthored
Deduplicate entries under "This technique relates to" (#4644)
Fixes #4576. This deduplicates any instance where a technique lists the same associated SC twice, where the first entry has no further qualification but the subsequent entries do. This only affects the About this Technique box on 3 pages: - ARIA16 - [before](https://w3c.github.io/wcag/techniques/aria/ARIA16) / [after](https://deploy-preview-4644--wcag2.netlify.app/techniques/aria/aria16) - G57 - [before](https://w3c.github.io/wcag/techniques/general/G57) / [after](https://deploy-preview-4644--wcag2.netlify.app/techniques/general/g57) - G91 - [before](https://w3c.github.io/wcag/techniques/general/G91) / [after](https://deploy-preview-4644--wcag2.netlify.app/techniques/general/g91) Co-authored-by: Mike Gower <[email protected]>
1 parent a2f5b1a commit 5faa1ad

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

11ty/techniques.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,10 +272,28 @@ export async function getTechniqueAssociations(
272272
}
273273

274274
// Remove duplicates (due to similar shape across understanding docs) and sort by SC number
275-
for (const [key, list] of Object.entries(associations))
276-
associations[key] = uniqBy(list, (v) => JSON.stringify(v)).sort((a, b) =>
275+
for (const [key, list] of Object.entries(associations)) {
276+
const deduplicatedList = uniqBy(list, (v) => JSON.stringify(v)).sort((a, b) =>
277277
wcagSort(a.criterion, b.criterion)
278278
);
279+
// Remove entries that are redundant of a more generalized preceding entry
280+
for (let i = 1; i < deduplicatedList.length; i++) {
281+
const previousEntry = deduplicatedList[i - 1];
282+
const entry = deduplicatedList[i];
283+
if (
284+
entry.criterion.id === previousEntry.criterion.id &&
285+
entry.type === previousEntry.type &&
286+
!previousEntry.hasUsageChildren &&
287+
!previousEntry.usageParentDescription &&
288+
!previousEntry.usageParentIds.length &&
289+
!previousEntry.with.length
290+
) {
291+
deduplicatedList.splice(i, 1);
292+
i--; // Next item is now in this index; repeat processing it
293+
}
294+
}
295+
associations[key] = deduplicatedList;
296+
}
279297

280298
return associations;
281299
}

0 commit comments

Comments
 (0)