Skip to content

Commit

Permalink
2.1 support: Pin ACT mappings to requested version
Browse files Browse the repository at this point in the history
  • Loading branch information
kfranqueiro committed Sep 30, 2024
1 parent 8ba9034 commit be10822
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
20 changes: 15 additions & 5 deletions 11ty/guidelines.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { readFile } from "fs/promises";
import { basename } from "path";

import { flattenDomFromFile, load } from "./cheerio";
import { generateId } from "./common";
import { generateId, resolveDecimalVersion } from "./common";

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

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

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

/**
* Retrieves act-mapping.json data for test-rules sections, pinned to an earlier WCAG version.
*/
export const getActRulesForVersion = async (version: WcagVersion) => {
return (
await axios.get<ActMapping>(
`https://raw.githubusercontent.com/w3c/wcag/refs/heads/WCAG-${resolveDecimalVersion(version)}/guidelines/act-mapping.json`
)
).data["act-rules"];
};

/**
* Retrieves and processes a pinned WCAG version using published guidelines.
*/
Expand Down
7 changes: 6 additions & 1 deletion eleventy.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import { copyFile } from "fs/promises";
import { CustomLiquid } from "11ty/CustomLiquid";
import { resolveDecimalVersion } from "11ty/common";
import {
actRules,
assertIsWcagVersion,
getActRules,
getActRulesForVersion,
getFlatGuidelines,
getPrinciples,
getPrinciplesForVersion,
Expand Down Expand Up @@ -46,6 +47,10 @@ const isTechniqueObsolete = (technique: Technique | undefined) =>
const isGuidelineObsolete = (guideline: Principle | Guideline | SuccessCriterion | undefined) =>
guideline?.type === "SC" && guideline.level === "";

const actRules = process.env.WCAG_VERSION
? await getActRulesForVersion(version)
: await getActRules();

/** Tree of Principles/Guidelines/SC across all versions (including later than selected) */
const allPrinciples = await getPrinciples();
/** Flattened Principles/Guidelines/SC across all versions (including later than selected) */
Expand Down

0 comments on commit be10822

Please sign in to comment.