Skip to content

Commit 89e7593

Browse files
committed
2.1 support: Pin ACT mappings to requested version
1 parent 8ba9034 commit 89e7593

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

11ty/guidelines.ts

+14-5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { readFile } from "fs/promises";
66
import { basename } from "path";
77

88
import { flattenDomFromFile, load } from "./cheerio";
9-
import { generateId } from "./common";
9+
import { generateId, resolveDecimalVersion } from "./common";
1010

1111
export type WcagVersion = "20" | "21" | "22";
1212
export function assertIsWcagVersion(v: string): asserts v is WcagVersion {
@@ -29,10 +29,9 @@ type ActMapping = {
2929
"act-rules": ActRule[];
3030
};
3131

32-
/** Data used for test-rules sections, from act-mapping.json */
33-
export const actRules = (
34-
JSON.parse(await readFile("guidelines/act-mapping.json", "utf8")) as ActMapping
35-
)["act-rules"];
32+
/** Retrieves act-mapping.json data for test-rules sections. */
33+
export const getActRules = async () =>
34+
(JSON.parse(await readFile("guidelines/act-mapping.json", "utf8")) as ActMapping)["act-rules"];
3635

3736
/**
3837
* Flattened object hash, mapping each WCAG 2 SC slug to the earliest WCAG version it applies to.
@@ -281,6 +280,16 @@ export const getAcknowledgementsForVersion = async (version: WcagVersion) => {
281280
return subsections;
282281
};
283282

283+
/**
284+
* Retrieves act-mapping.json data for test-rules sections, pinned to an earlier WCAG version.
285+
*/
286+
export const getActRulesForVersion = async (version: WcagVersion) =>
287+
(
288+
await axios.get<ActMapping>(
289+
`https://raw.githubusercontent.com/w3c/wcag/refs/heads/WCAG-${resolveDecimalVersion(version)}/guidelines/act-mapping.json`
290+
)
291+
).data["act-rules"];
292+
284293
/**
285294
* Retrieves and processes a pinned WCAG version using published guidelines.
286295
*/

eleventy.config.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ import { copyFile } from "fs/promises";
55
import { CustomLiquid } from "11ty/CustomLiquid";
66
import { resolveDecimalVersion } from "11ty/common";
77
import {
8-
actRules,
98
assertIsWcagVersion,
9+
getActRules,
10+
getActRulesForVersion,
1011
getFlatGuidelines,
1112
getPrinciples,
1213
getPrinciplesForVersion,
@@ -46,6 +47,10 @@ const isTechniqueObsolete = (technique: Technique | undefined) =>
4647
const isGuidelineObsolete = (guideline: Principle | Guideline | SuccessCriterion | undefined) =>
4748
guideline?.type === "SC" && guideline.level === "";
4849

50+
const actRules = process.env.WCAG_VERSION
51+
? await getActRulesForVersion(version)
52+
: await getActRules();
53+
4954
/** Tree of Principles/Guidelines/SC across all versions (including later than selected) */
5055
const allPrinciples = await getPrinciples();
5156
/** Flattened Principles/Guidelines/SC across all versions (including later than selected) */

0 commit comments

Comments
 (0)