Skip to content

Commit 2d76e8d

Browse files
authored
JSON: Restore full technique titles within techniquesHtml (#4412)
The implementation of the `techniquesHtml` field in #4301 comes directly from the already-built Understanding pages. These include logic to truncate particularly long titles when linking to techniques. This is similar to what was done in the XSLT build processes both for the informative docs and `wcag.json`, except that the new build system includes a visible ellipsis where content was truncated. For the purposes of JSON output, it makes more sense to give consumers access to the full title, leaving them free to do what they want with it. Since the build process for the JSON output already processes links to make them absolute, this adds more processing to also fully expand their titles within the same loop. This impacts relatively few techniques, many of which are enumerated in #4393.
1 parent c40269f commit 2d76e8d

File tree

1 file changed

+26
-7
lines changed

1 file changed

+26
-7
lines changed

11ty/json.ts

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,15 @@ import {
1313
getPrinciplesForVersion,
1414
getTermsMapForVersion,
1515
assertIsWcagVersion,
16+
getFlatGuidelines,
1617
} from "./guidelines";
17-
import { techniqueAssociationTypes, type TechniqueAssociationType } from "./techniques";
18+
import {
19+
getFlatTechniques,
20+
getTechniquesByTechnology,
21+
techniqueAssociationTypes,
22+
type Technique,
23+
type TechniqueAssociationType,
24+
} from "./techniques";
1825

1926
const altIds: Record<string, string> = {
2027
"text-alternatives": "text-equiv",
@@ -197,7 +204,10 @@ interface TechniquesSituation {
197204

198205
type TechniquesHtmlMap = Partial<Record<TechniqueAssociationType, string | TechniquesSituation[]>>;
199206

200-
async function createTechniquesHtmlFromSc(sc: SuccessCriterion) {
207+
async function createTechniquesHtmlFromSc(
208+
sc: SuccessCriterion,
209+
techniquesMap: Record<string, Technique>
210+
) {
201211
const $ = await loadFromFile(join("_site", "understanding", `${sc.id}.html`));
202212

203213
function cleanHtml($el: CheerioElement) {
@@ -236,11 +246,17 @@ async function createTechniquesHtmlFromSc(sc: SuccessCriterion) {
236246
// Make techniques links absolute
237247
// (this uses a different selector than the build process, to handle pre-built output)
238248
$section.find("[href*='/techniques/' i]").each((_, el) => {
239-
el.attribs.href = el.attribs["href"].replace(
240-
/^.*\/([\w-]+\/[^\/]+)$/,
241-
"https://www.w3.org/WAI/WCAG22/Techniques/$1"
249+
const $el = $(el);
250+
const technique = techniquesMap[$el.attr("href")!.replace(/^.*\//, "")];
251+
$el.attr(
252+
"href",
253+
$el
254+
.attr("href")!
255+
.replace(/^.*\/([\w-]+\/[^\/]+)$/, "https://www.w3.org/WAI/WCAG22/Techniques/$1")
242256
);
243-
delete el.attribs.class;
257+
$el.removeAttr("class");
258+
// Restore full title (whereas links in build output used truncatedTitle)
259+
$el.html(`${technique.id}: ${technique.title.replace(/\n\s+/g, " ")}`);
244260
});
245261

246262
// Remove superfluous subheadings/subsections, e.g. "CSS Techniques (Advisory)"
@@ -299,6 +315,9 @@ export async function generateWcagJson(version: WcagVersion) {
299315
includeSynonyms: false,
300316
stripRespec: false,
301317
});
318+
const techniquesMap = getFlatTechniques(
319+
await getTechniquesByTechnology(getFlatGuidelines(principles))
320+
);
302321

303322
function cleanLinks($: CheerioAPI) {
304323
$("a[href]").each((_, aEl) => {
@@ -337,7 +356,7 @@ export async function generateWcagJson(version: WcagVersion) {
337356
...spreadCommonProps(sc),
338357
level: sc.level,
339358
details: createDetailsFromSc(sc),
340-
techniquesHtml: await createTechniquesHtmlFromSc(sc),
359+
techniquesHtml: await createTechniquesHtmlFromSc(sc, techniquesMap),
341360
}))
342361
),
343362
}))

0 commit comments

Comments
 (0)