Skip to content

Commit

Permalink
2.1 support: Use acknowledgments content from pinned version
Browse files Browse the repository at this point in the history
  • Loading branch information
kfranqueiro committed Aug 22, 2024
1 parent 6978a2a commit b5a5efc
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 33 deletions.
10 changes: 9 additions & 1 deletion 11ty/CustomLiquid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type { GlobalData } from "eleventy.config";

import { flattenDom, load } from "./cheerio";
import { generateId } from "./common";
import { getTermsMap } from "./guidelines";
import { getAcknowledgementsForVersion, getTermsMap } from "./guidelines";
import { resolveTechniqueIdFromHref, understandingToTechniqueLinkSelector } from "./techniques";
import { techniqueToUnderstandingLinkSelector } from "./understanding";

Expand Down Expand Up @@ -304,6 +304,14 @@ export class CustomLiquid extends Liquid {
if (indexPattern.test(scope.page.inputPath)) {
// Remove empty list items due to obsolete technique link removal
if (scope.isTechniques) $("ul.toc-wcag-docs li:empty").remove();

// Replace acknowledgements with pinned content for older versions
if (process.env.WCAG_VERSION && $("section#acknowledgements").length) {
const pinnedAcknowledgements = await getAcknowledgementsForVersion(scope.version);
for (const [id, content] of Object.entries(pinnedAcknowledgements)) {
$(`#${id} h3 +`).html(content);
}
}
} else {
const $title = $("title");

Expand Down
87 changes: 59 additions & 28 deletions 11ty/guidelines.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,34 +171,6 @@ function processPrinciples($: CheerioAPI) {
export const getPrinciples = async () =>
processPrinciples(await flattenDomFromFile("guidelines/index.html"));

/**
* Retrieves and processes a pinned WCAG version using published guidelines.
*/
export const getPrinciplesForVersion = async (version: WcagVersion) => {
const $ = load(
(await axios.get(`https://www.w3.org/TR/WCAG${version}/`, { responseType: "text" })).data
);

// Re-collapse definition links and notes, to be processed by this build system
$(".guideline a.internalDFN").removeAttr("class data-link-type id href title");
$(".guideline [role='note'] .marker").remove();
$(".guideline [role='note']").find("> div, > p").addClass("note").unwrap();

// Bibliography references are not processed in Understanding SC boxes
$(".guideline cite:has(a.bibref:only-child)").each((_, el) => {
const $el = $(el);
const $parent = $el.parent();
$el.remove();
// Remove surrounding square brackets (which aren't in a dedicated element)
$parent.html($parent.html()!.replace(/ \[\]/g, ""));
});

// Remove extra markup from headings so they can be parsed for names
$("bdi").remove();

return processPrinciples($);
};

/**
* Returns a flattened object hash, mapping shortcodes to each principle/guideline/SC.
*/
Expand Down Expand Up @@ -255,3 +227,62 @@ export async function getTermsMap() {

return terms;
}

// Version-specific APIs

const remoteGuidelines$: Partial<Record<WcagVersion, CheerioAPI>> = {};

/** Loads guidelines from TR space for specific version, caching for future calls. */
const loadRemoteGuidelines = async (version: WcagVersion) => {
if (!remoteGuidelines$[version]) {
const $ = load(
(await axios.get(`https://www.w3.org/TR/WCAG${version}/`, { responseType: "text" })).data
);

// Re-collapse definition links and notes, to be processed by this build system
$(".guideline a.internalDFN").removeAttr("class data-link-type id href title");
$(".guideline [role='note'] .marker").remove();
$(".guideline [role='note']").find("> div, > p").addClass("note").unwrap();

// Bibliography references are not processed in Understanding SC boxes
$(".guideline cite:has(a.bibref:only-child)").each((_, el) => {
const $el = $(el);
const $parent = $el.parent();
$el.remove();
// Remove surrounding square brackets (which aren't in a dedicated element)
$parent.html($parent.html()!.replace(/ \[\]/g, ""));
});

// Remove extra markup from headings so they can be parsed for names
$("bdi").remove();

// Remove abbr elements which exist only in TR, not in informative docs
$("#acknowledgements li abbr").each((_, abbrEl) => {
$(abbrEl).replaceWith($(abbrEl).text());
});

remoteGuidelines$[version] = $;
}
return remoteGuidelines$[version]!;
};

/**
* Retrieves heading and content information for acknowledgement subsections,
* for preserving the section in About pages for earlier versions.
*/
export const getAcknowledgementsForVersion = async (version: WcagVersion) => {
const $ = await loadRemoteGuidelines(version);
const subsections: Record<string, string> = {};

$("section#acknowledgements section").each((_, el) => {
subsections[el.attribs.id] = $(".header-wrapper + *", el).html()!;
});

return subsections;
};

/**
* Retrieves and processes a pinned WCAG version using published guidelines.
*/
export const getPrinciplesForVersion = async (version: WcagVersion) =>
processPrinciples(await loadRemoteGuidelines(version));
4 changes: 2 additions & 2 deletions acknowledgements/ag-contributors.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<section id="ack_participants-previous">
<h2>Other previously active WCAG WG participants and other contributors to WCAG 2.0, WCAG 2.1, or supporting resources </h2>
<h3>Other previously active WCAG WG participants and other contributors to WCAG 2.0, WCAG 2.1, or supporting resources </h3>
<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>
</section>
</section>
2 changes: 1 addition & 1 deletion acknowledgements/ag-wg-active.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<section id="ack_participants-active">
<h2>Participants of the AG WG active in the development of this document:</h2>
<h3>Participants of the AG WG active in the development of this document:</h3>
<ul>
<li>Jake Abma (Invited Expert)</li>
<li>Shadi Abou-Zahra (Amazon)</li>
Expand Down
2 changes: 1 addition & 1 deletion acknowledgements/funders.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<section id="enabling-funders">
<h2>Enabling funders</h2>
<h3>Enabling funders</h3>
<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>
</section>

0 comments on commit b5a5efc

Please sign in to comment.