Skip to content

Commit b5a5efc

Browse files
committed
2.1 support: Use acknowledgments content from pinned version
1 parent 6978a2a commit b5a5efc

File tree

5 files changed

+72
-33
lines changed

5 files changed

+72
-33
lines changed

11ty/CustomLiquid.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import type { GlobalData } from "eleventy.config";
1010

1111
import { flattenDom, load } from "./cheerio";
1212
import { generateId } from "./common";
13-
import { getTermsMap } from "./guidelines";
13+
import { getAcknowledgementsForVersion, getTermsMap } from "./guidelines";
1414
import { resolveTechniqueIdFromHref, understandingToTechniqueLinkSelector } from "./techniques";
1515
import { techniqueToUnderstandingLinkSelector } from "./understanding";
1616

@@ -304,6 +304,14 @@ export class CustomLiquid extends Liquid {
304304
if (indexPattern.test(scope.page.inputPath)) {
305305
// Remove empty list items due to obsolete technique link removal
306306
if (scope.isTechniques) $("ul.toc-wcag-docs li:empty").remove();
307+
308+
// Replace acknowledgements with pinned content for older versions
309+
if (process.env.WCAG_VERSION && $("section#acknowledgements").length) {
310+
const pinnedAcknowledgements = await getAcknowledgementsForVersion(scope.version);
311+
for (const [id, content] of Object.entries(pinnedAcknowledgements)) {
312+
$(`#${id} h3 +`).html(content);
313+
}
314+
}
307315
} else {
308316
const $title = $("title");
309317

11ty/guidelines.ts

+59-28
Original file line numberDiff line numberDiff line change
@@ -171,34 +171,6 @@ function processPrinciples($: CheerioAPI) {
171171
export const getPrinciples = async () =>
172172
processPrinciples(await flattenDomFromFile("guidelines/index.html"));
173173

174-
/**
175-
* Retrieves and processes a pinned WCAG version using published guidelines.
176-
*/
177-
export const getPrinciplesForVersion = async (version: WcagVersion) => {
178-
const $ = load(
179-
(await axios.get(`https://www.w3.org/TR/WCAG${version}/`, { responseType: "text" })).data
180-
);
181-
182-
// Re-collapse definition links and notes, to be processed by this build system
183-
$(".guideline a.internalDFN").removeAttr("class data-link-type id href title");
184-
$(".guideline [role='note'] .marker").remove();
185-
$(".guideline [role='note']").find("> div, > p").addClass("note").unwrap();
186-
187-
// Bibliography references are not processed in Understanding SC boxes
188-
$(".guideline cite:has(a.bibref:only-child)").each((_, el) => {
189-
const $el = $(el);
190-
const $parent = $el.parent();
191-
$el.remove();
192-
// Remove surrounding square brackets (which aren't in a dedicated element)
193-
$parent.html($parent.html()!.replace(/ \[\]/g, ""));
194-
});
195-
196-
// Remove extra markup from headings so they can be parsed for names
197-
$("bdi").remove();
198-
199-
return processPrinciples($);
200-
};
201-
202174
/**
203175
* Returns a flattened object hash, mapping shortcodes to each principle/guideline/SC.
204176
*/
@@ -255,3 +227,62 @@ export async function getTermsMap() {
255227

256228
return terms;
257229
}
230+
231+
// Version-specific APIs
232+
233+
const remoteGuidelines$: Partial<Record<WcagVersion, CheerioAPI>> = {};
234+
235+
/** Loads guidelines from TR space for specific version, caching for future calls. */
236+
const loadRemoteGuidelines = async (version: WcagVersion) => {
237+
if (!remoteGuidelines$[version]) {
238+
const $ = load(
239+
(await axios.get(`https://www.w3.org/TR/WCAG${version}/`, { responseType: "text" })).data
240+
);
241+
242+
// Re-collapse definition links and notes, to be processed by this build system
243+
$(".guideline a.internalDFN").removeAttr("class data-link-type id href title");
244+
$(".guideline [role='note'] .marker").remove();
245+
$(".guideline [role='note']").find("> div, > p").addClass("note").unwrap();
246+
247+
// Bibliography references are not processed in Understanding SC boxes
248+
$(".guideline cite:has(a.bibref:only-child)").each((_, el) => {
249+
const $el = $(el);
250+
const $parent = $el.parent();
251+
$el.remove();
252+
// Remove surrounding square brackets (which aren't in a dedicated element)
253+
$parent.html($parent.html()!.replace(/ \[\]/g, ""));
254+
});
255+
256+
// Remove extra markup from headings so they can be parsed for names
257+
$("bdi").remove();
258+
259+
// Remove abbr elements which exist only in TR, not in informative docs
260+
$("#acknowledgements li abbr").each((_, abbrEl) => {
261+
$(abbrEl).replaceWith($(abbrEl).text());
262+
});
263+
264+
remoteGuidelines$[version] = $;
265+
}
266+
return remoteGuidelines$[version]!;
267+
};
268+
269+
/**
270+
* Retrieves heading and content information for acknowledgement subsections,
271+
* for preserving the section in About pages for earlier versions.
272+
*/
273+
export const getAcknowledgementsForVersion = async (version: WcagVersion) => {
274+
const $ = await loadRemoteGuidelines(version);
275+
const subsections: Record<string, string> = {};
276+
277+
$("section#acknowledgements section").each((_, el) => {
278+
subsections[el.attribs.id] = $(".header-wrapper + *", el).html()!;
279+
});
280+
281+
return subsections;
282+
};
283+
284+
/**
285+
* Retrieves and processes a pinned WCAG version using published guidelines.
286+
*/
287+
export const getPrinciplesForVersion = async (version: WcagVersion) =>
288+
processPrinciples(await loadRemoteGuidelines(version));

acknowledgements/ag-contributors.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
<section id="ack_participants-previous">
2-
<h2>Other previously active WCAG WG participants and other contributors to WCAG 2.0, WCAG 2.1, or supporting resources </h2>
2+
<h3>Other previously active WCAG WG participants and other contributors to WCAG 2.0, WCAG 2.1, or supporting resources </h3>
33
<p>Paul Adam, Jenae Andershonis, Wilhelm Joys Andersen, Andrew Arch, Avi Arditti, Aries Arditi, Tom Babinszki, Mark Barratt, Mike Barta, Sandy Bartell, Kynn Bartlett, Chris Beer, Charles Belov, Marco Bertoni, Harvey Bingham, Chris Blouch, Paul Bohman, Frederick Boland, Denis Boudreau, Patrice Bourlon, Andy Brown, Dick Brown, Doyle Burnett, Raven Calais, Ben Caldwell, Tomas Caspers, Roberto Castaldo, Sofia Celic-Li, Sambhavi Chandrashekar, Mike Cherim, Jonathan Chetwynd, Wendy Chisholm, Alan Chuter, David M Clark, Joe Clark, Darcy Clarke, James Coltham, Earl Cousins, James Craig, Tom Croucher, Pierce Crowell, Nir Dagan, Daniel Dardailler, Geoff Deering, Sébastien Delorme, Pete DeVasto, Iyad Abu Doush, Sylvie Duchateau, Cherie Eckholm, Roberto Ellero, Don Evans, Gavin Evans, Neal Ewers, Steve Faulkner, Bengt Farre, Lainey Feingold, Wilco Fiers, Michel Fitos, Alan J. Flavell, Nikolaos Floratos, Kentarou Fukuda, Miguel Garcia, P.J. Gardner, Alistair Garrison, Greg Gay, Becky Gibson, Al Gilman, Kerstin Goldsmith, Michael Grade, Karl Groves, Loretta Guarino Reid, Jon Gunderson, Emmanuelle Gutiérrez y Restrepo, Brian Hardy, Eric Hansen, Benjamin Hawkes-Lewis, Sean Hayes, Shawn Henry, Hans Hillen, Donovan Hipke, Bjoern Hoehrmann, Allen Hoffman, Chris Hofstader, Yvette Hoitink, Martijn Houtepen, Carlos Iglesias, Richard Ishida, Jonas Jacek, Ian Jacobs, Phill Jenkins, Barry Johnson, Duff Johnson, Jyotsna Kaki, Shilpi Kapoor, Leonard R. Kasday, Kazuhito Kidachi, Ken Kipness, Johannes Koch, Marja-Riitta Koivunen, Maureen Kraft, Preety Kumar, Kristjan Kure, Andrew LaHart, Gez Lemon, Chuck Letourneau, Aurélien Levy, Harry Loots, Scott Luebking, Tim Lacy, Jim Ley, Alex Li, William Loughborough, N Maffeo, Mark Magennis, Erich Manser, Kapsi Maria, Luca Mascaro, Matt May, Sheena McCullagh, Liam McGee, Jens Oliver Meiert, Niqui Merret, Jonathan Metz, Alessandro Miele, Steven Miller, Mathew J Mirabella, Matt May, Marti McCuller, Sorcha Moore, Charles F. Munat, Robert Neff, Charles Nevile, Liddy Nevile, Dylan Nicholson, Bruno von Niman, Tim Noonan, Sebastiano Nutarelli, Graham Oliver, Sean B. Palmer, Charu Pandhi, evarshi Pant, Nigel Peck, Anne Pemberton, David Poehlman, Ian Pouncey, Charles Pritchard, Kerstin Probiesch, W Reagan, Adam Victor Reed, Chris Reeve, Chris Ridpath, Lee Roberts, Mark Rogers, Raph de Rooij, Gregory J. Rosmaita, Matthew Ross, Sharron Rush, Joel Sanda, Janina Sajka, Roberto Scano, Gordon Schantz, Tim van Schie, Wolf Schmidt, Stefan Schnabel, Cynthia Shelly, Glenda Sims, John Slatin, Becky Smith, Jared Smith, Andi Snow-Weaver, Neil Soiffer, Mike Squillace, Michael Stenitzer, Diane Stottlemyer, Christophe Strobbe, Sarah J Swierenga, Jim Thatcher, Terry Thompson, Justin Thorp, David Todd, Mary Utt, Jean Vanderdonckt, Carlos A Velasco, Eric Velleman, Gijs Veyfeyken, Dena Wainwright, Paul Walsch, Daman Wandke, Richard Warren, Elle Waters, Takayuki Watanabe, Gian Wild, David Wooley, Wu Wei, Kenny Zhang, Leona Zumbo.</p>
4-
</section>
4+
</section>

acknowledgements/ag-wg-active.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<section id="ack_participants-active">
2-
<h2>Participants of the AG WG active in the development of this document:</h2>
2+
<h3>Participants of the AG WG active in the development of this document:</h3>
33
<ul>
44
<li>Jake Abma (Invited Expert)</li>
55
<li>Shadi Abou-Zahra (Amazon)</li>

acknowledgements/funders.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
<section id="enabling-funders">
2-
<h2>Enabling funders</h2>
2+
<h3>Enabling funders</h3>
33
<p>This publication has been funded in part with U.S. Federal funds from the Health and Human Services, National Institute on Disability, Independent Living, and Rehabilitation Research (NIDILRR), initially under contract number ED-OSE-10-C-0067, then under contract number HHSP23301500054C, and now under HHS75P00120P00168. The content of this publication does not necessarily reflect the views or policies of the U.S. Department of Health and Human Services or the U.S. Department of Education, nor does mention of trade names, commercial products, or organizations imply endorsement by the U.S. Government.</p>
44
</section>

0 commit comments

Comments
 (0)