Skip to content

Commit 7e0f5ea

Browse files
authored
Add top-level index.html for dev only (not GH Pages / W3C site) (#4081)
This is a re-do of #4076, with one change: it only pre-clears the output folder (`_site`) for W3C site builds, not for GitHub Pages builds. The deploy script for the latter depends on the output folder _not_ being cleared, in order to layer the new build on top of existing contents. (Fortunately this failed loudly the first time upon deploy, so it didn't affect the contents of the gh-pages branch.) I tested using my own fork this time to make sure the GitHub Pages build would complete, and confirmed that the top-level index.html added in this PR does _not_ output for that build, leaving the existing top-level index.html in the gh-pages branch intact.
1 parent 17baae9 commit 7e0f5ea

6 files changed

+28
-1
lines changed

.eleventyignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
*.*
1+
*.md
22
11ty/
3+
acknowledgements.html
34
acknowledgements/
45
conformance-challenges/
56
guidelines/

11ty/CustomLiquid.ts

+2
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ export class CustomLiquid extends Liquid {
8989
const isIndex = indexPattern.test(filepath);
9090
const isTechniques = techniquesPattern.test(filepath);
9191
const isUnderstanding = understandingPattern.test(filepath);
92+
93+
if (!isTechniques && !isUnderstanding) return super.parse(html);
9294

9395
const $ = flattenDom(html, filepath);
9496

eleventy.config.ts

+8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import compact from "lodash-es/compact";
2+
import { rimraf } from "rimraf";
23

34
import { copyFile } from "fs/promises";
45

@@ -124,6 +125,7 @@ export default function (eleventyConfig: any) {
124125
eleventyConfig.addGlobalData("eleventyComputed", {
125126
// permalink determines output structure; see https://www.11ty.dev/docs/permalinks/
126127
permalink: ({ page, isUnderstanding }: GlobalData) => {
128+
if (page.inputPath === "./index.html" && process.env.WCAG_MODE) return false;
127129
if (isUnderstanding) {
128130
// understanding-metadata.html exists in 2 places; top-level wins in XSLT process
129131
if (/\/20\/understanding-metadata/.test(page.inputPath)) return false;
@@ -173,6 +175,12 @@ export default function (eleventyConfig: any) {
173175

174176
eleventyConfig.addPassthroughCopy("working-examples/**");
175177

178+
eleventyConfig.on("eleventy.before", async ({ runMode }: EleventyEvent) => {
179+
// Clear the _site folder before builds intended for the W3C site,
180+
// to avoid inheriting dev-only files from previous runs
181+
if (runMode === "build" && process.env.WCAG_MODE === "publication") await rimraf("_site");
182+
});
183+
176184
eleventyConfig.on("eleventy.after", async ({ dir }: EleventyEvent) => {
177185
// addPassthroughCopy can only map each file once,
178186
// but base.css needs to be copied to a 2nd destination

index.html

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8"/>
5+
<title>Web Content Accessibility Guidelines {{ versionDecimal }}</title>
6+
</head>
7+
<body>
8+
<h1>Web Content Accessibility Guidelines {{ versionDecimal }}</h1>
9+
<ul>
10+
<li><a href="techniques/">Techniques</a></li>
11+
<li><a href="understanding/">Understanding Docs</a></li>
12+
</ul>
13+
</body>
14+
</html>

package-lock.json

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"liquidjs": "^10.17.0",
2222
"lodash-es": "^4.17.21",
2323
"mkdirp": "^3.0.1",
24+
"rimraf": "^5.0.10",
2425
"tsx": "^4.11.0"
2526
},
2627
"devDependencies": {

0 commit comments

Comments
 (0)