Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Eleventy build: Support generating WCAG 2.1 docs from main branch #4007

Open
wants to merge 24 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
4ae473c
WIP Add support for generating WCAG 2.1 from main branch
kfranqueiro Jul 10, 2024
dfb8749
2.1 support: Pin against published guidelines, fix permalink filter
kfranqueiro Jul 15, 2024
63585fe
2.1 support: Universally update version in titles/h1s of other docs
kfranqueiro Jul 16, 2024
7fb141b
2.1 support: Replace hard-coded version references in refer-to-wcag
kfranqueiro Jul 16, 2024
7f74093
2.1 support: Update hard-coded version in understanding-techniques
kfranqueiro Jul 16, 2024
0d4d4e7
Add support for an element being both wcagXY and note
kfranqueiro Jul 16, 2024
6306ff3
2.1: Add wcag22 class to 2.2-specific three-flashes-or-below note
kfranqueiro Jul 16, 2024
ce1807e
2.1: Conditionalize 2.2 SC reference in pointer-gestures
kfranqueiro Jul 16, 2024
c798821
2.1 support: Avoid linking to future-version-only techniques
kfranqueiro Jul 18, 2024
421b7e6
2.1 support: Reference variable for version in index pages
kfranqueiro Jul 19, 2024
133d6ec
Fix slug-in-version check to account for mapped slugs
kfranqueiro Aug 12, 2024
1c6bb14
Preserve W3C staff contact attribution in < 2.2
kfranqueiro Aug 22, 2024
e249bb8
2.1 support: Use acknowledgments content from pinned version
kfranqueiro Aug 22, 2024
c0f95d9
Update npm dependencies for security fixes
kfranqueiro Sep 30, 2024
7c42123
2.1 support: Pin ACT mappings to requested version
kfranqueiro Sep 30, 2024
1b58864
Remove paragraph from target-size-enhanced that duplicates template
kfranqueiro Sep 30, 2024
7cd97a8
Update Intro and Understanding Techniques to reference specific version
kfranqueiro Oct 1, 2024
8c5535d
Re-simplify title logic for other understanding docs
kfranqueiro Oct 1, 2024
81d5d1a
Revert "2.1 support: Pin ACT mappings to requested version"
kfranqueiro Oct 7, 2024
8b6e9af
Move techniques changelog to version-specific files
kfranqueiro Oct 9, 2024
b550bae
Add 2.1 variant of publish-w3c script
kfranqueiro Oct 9, 2024
c56abbb
Formatting pass
kfranqueiro Oct 9, 2024
312c92a
Fix Cheerio 1.0.0 type errors
kfranqueiro Oct 9, 2024
895e0b1
2.1 support: Prune future-version SCs from technique titles
kfranqueiro Nov 8, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 28 additions & 13 deletions 11ty/CustomLiquid.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import type { Cheerio, Element } from "cheerio";
import { Liquid, type Template } from "liquidjs";
import type { RenderOptions } from "liquidjs/dist/liquid-options";
import compact from "lodash-es/compact";
Expand All @@ -8,9 +7,9 @@ import { basename } from "path";

import type { GlobalData } from "eleventy.config";

import { flattenDom, load } from "./cheerio";
import { flattenDom, load, type CheerioAnyNode } 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 @@ -61,7 +60,7 @@ const normalizeTocLabel = (label: string) =>
* expand to a link with the full technique ID and title.
* @param $el a $()-wrapped link element
*/
function expandTechniqueLink($el: Cheerio<Element>) {
function expandTechniqueLink($el: CheerioAnyNode) {
const href = $el.attr("href");
if (!href) throw new Error("expandTechniqueLink: non-link element encountered");
const id = resolveTechniqueIdFromHref(href);
Expand Down Expand Up @@ -89,7 +88,7 @@ export class CustomLiquid extends Liquid {
const isIndex = indexPattern.test(filepath);
const isTechniques = techniquesPattern.test(filepath);
const isUnderstanding = understandingPattern.test(filepath);

if (!isTechniques && !isUnderstanding) return super.parse(html);

const $ = flattenDom(html, filepath);
Expand Down Expand Up @@ -306,6 +305,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 Expand Up @@ -399,7 +406,7 @@ export class CustomLiquid extends Liquid {
// Process defined terms within #render,
// where we have access to global data and the about box's HTML
const $termLinks = $(termLinkSelector);
const extractTermName = ($el: Cheerio<Element>) => {
const extractTermName = ($el: CheerioAnyNode) => {
const name = $el
.text()
.toLowerCase()
Expand All @@ -424,7 +431,7 @@ export class CustomLiquid extends Liquid {
});
} else if (scope.isUnderstanding) {
const $termsList = $("section#key-terms dl");
const extractTermNames = ($links: Cheerio<Element>) =>
const extractTermNames = ($links: CheerioAnyNode) =>
compact(uniq($links.toArray().map((el) => extractTermName($(el)))));

if ($termLinks.length) {
Expand Down Expand Up @@ -494,20 +501,22 @@ export class CustomLiquid extends Liquid {
// (This is also needed for techniques/about)
$("div.note").each((_, el) => {
const $el = $(el);
$el.replaceWith(`<div class="note">
const classes = el.attribs.class;
$el.replaceWith(`<div class="${classes}">
<p class="note-title marker">Note</p>
<div>${$el.html()}</div>
</div>`);
});
// Handle p variant after div (the reverse would double-process)
$("p.note").each((_, el) => {
const $el = $(el);
$el.replaceWith(`<div class="note">
const classes = el.attribs.class;
$el.replaceWith(`<div class="${classes}">
<p class="note-title marker">Note</p>
<p>${$el.html()}</p>
</div>`);
});

// Add header to example sections in Key Terms (aside) and Conformance (div)
$("aside.example, div.example").each((_, el) => {
const $el = $(el);
Expand All @@ -520,13 +529,19 @@ export class CustomLiquid extends Liquid {
// Handle new-in-version content
$("[class^='wcag']").each((_, el) => {
// Just like the XSLT process, this naively assumes that version numbers are the same length
const classVersion = +el.attribs.class.replace(/^wcag/, "");
const buildVersion = +scope.version;
const classMatch = el.attribs.class.match(/\bwcag(\d\d)\b/);
if (!classMatch) throw new Error(`Invalid wcagXY class found: ${el.attribs.class}`);
const classVersion = +classMatch[1];
if (isNaN(classVersion)) throw new Error(`Invalid wcagXY class found: ${el.attribs.class}`);
const buildVersion = +scope.version;

if (classVersion > buildVersion) {
$(el).remove();
} else if (classVersion === buildVersion) {
$(el).prepend(`<span class="new-version">New in WCAG ${scope.versionDecimal}: </span>`);
if (/\bnote\b/.test(el.attribs.class))
$(el).find(".marker").append(` (new in WCAG ${scope.versionDecimal})`);
else
$(el).prepend(`<span class="new-version">New in WCAG ${scope.versionDecimal}: </span>`);
}
// Output as-is if content pertains to a version older than what's being built
});
Expand Down
8 changes: 5 additions & 3 deletions 11ty/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,14 @@ but may be useful if you're not seeing what you expect in the output files.

### `WCAG_VERSION`

**Usage context:** currently this should not be changed, pending future improvements to `21` support
**Usage context:** for building older versions of techniques and understanding docs

Indicates WCAG version being built, in `XY` format (i.e. no `.`).
Influences base URLs for links to guidelines, techniques, and understanding pages.
Influences which pages get included, guideline/SC content,
and a few details within pages (e.g. titles/URLs, "New in ..." content).
Also influences base URLs for links to guidelines, techniques, and understanding pages.

**Default:** `22`
Possible values: `22` **(default)**, `21`

### `WCAG_MODE`

Expand Down
3 changes: 3 additions & 0 deletions 11ty/cheerio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import { dirname, resolve } from "path";

export { load } from "cheerio";

/** Superset of the type returned by any Cheerio $() call. */
export type CheerioAnyNode = ReturnType<ReturnType<typeof load>>;

/** Convenience function that combines readFile and load. */
export const loadFromFile = async (
inputPath: string,
Expand Down
Loading