diff --git a/.github/workflows/11ty-publish.yaml b/.github/workflows/11ty-publish.yaml index adbb274be0..fd2ec74e6b 100644 --- a/.github/workflows/11ty-publish.yaml +++ b/.github/workflows/11ty-publish.yaml @@ -1,4 +1,4 @@ -name: CI +name: Push to gh-pages branch # Reference documentation: https://docs.github.com/en/actions/reference diff --git a/.pr-preview.json b/.pr-preview.json deleted file mode 100644 index bf7627ccb3..0000000000 --- a/.pr-preview.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "src_file": "guidelines/index.html", - "type": "respec" -} diff --git a/eleventy.config.ts b/eleventy.config.ts index fc9fe5ff69..abec817370 100644 --- a/eleventy.config.ts +++ b/eleventy.config.ts @@ -1,7 +1,10 @@ +import axios from "axios"; import compact from "lodash-es/compact"; +import { mkdirp } from "mkdirp"; import { rimraf } from "rimraf"; -import { copyFile } from "fs/promises"; +import { copyFile, writeFile } from "fs/promises"; +import { join } from "path"; import { CustomLiquid } from "11ty/CustomLiquid"; import { @@ -184,7 +187,31 @@ export default function (eleventyConfig: any) { eleventyConfig.on("eleventy.after", async ({ dir }: EleventyEvent) => { // addPassthroughCopy can only map each file once, // but base.css needs to be copied to a 2nd destination - await copyFile(`${dir.input}/css/base.css`, `${dir.output}/understanding/base.css`); + await copyFile( + join(dir.input, "css", "base.css"), + join(dir.output, "understanding", "base.css") + ); + + // Output guidelines/index.html and dependencies for PR runs (not for GH Pages or W3C site) + const sha = process.env.COMMIT_REF; // Read environment variable exposed by Netlify + if (sha && !process.env.WCAG_MODE) { + await mkdirp(join(dir.output, "guidelines")); + await copyFile( + join(dir.input, "guidelines", "guidelines.css"), + join(dir.output, "guidelines", "guidelines.css") + ); + await copyFile( + join(dir.input, "guidelines", "relative-luminance.html"), + join(dir.output, "guidelines", "relative-luminance.html") + ); + + const url = `https://raw.githack.com/${GH_ORG}/${GH_REPO}/${sha}/guidelines/index.html?isPreview=true`; + const { data: processedGuidelines } = await axios.get( + `https://labs.w3.org/spec-generator/?type=respec&url=${encodeURIComponent(url)}`, + { responseType: "text" } + ); + await writeFile(`${dir.output}/guidelines/index.html`, processedGuidelines); + } }); eleventyConfig.setLibrary( diff --git a/index.html b/index.html index 9fcfa92eb7..56183d90c5 100644 --- a/index.html +++ b/index.html @@ -1,3 +1,9 @@ +---js +// Same condition used for copying guidelines assets in eleventy.config.ts +const includeGuidelines = process.env.COMMIT_REF && !process.env.WCAG_MODE; +const repoUrl = process.env.REPOSITORY_URL; +const prNumber = process.env.REVIEW_ID; +--- @@ -6,7 +12,16 @@

Web Content Accessibility Guidelines {{ versionDecimal }}

+ {% if repoUrl and prNumber -%} +

+ Note: This is a preview for + PR #{{ prNumber }}. +

+ {%- endif %} diff --git a/package.json b/package.json index b481b35df8..156a3283e7 100644 --- a/package.json +++ b/package.json @@ -15,6 +15,7 @@ "license": "W3C", "dependencies": { "@11ty/eleventy": "^3.0.0", + "axios": "^1.7.7", "cheerio": "^1.0.0", "glob": "^10.3.16", "gray-matter": "^4.0.3",