|
| 1 | +import axios from "axios"; |
1 | 2 | import compact from "lodash-es/compact";
|
| 3 | +import { mkdirp } from "mkdirp"; |
2 | 4 | import { rimraf } from "rimraf";
|
3 | 5 |
|
4 |
| -import { copyFile } from "fs/promises"; |
| 6 | +import { copyFile, writeFile } from "fs/promises"; |
| 7 | +import { join } from "path"; |
5 | 8 |
|
6 | 9 | import { CustomLiquid } from "11ty/CustomLiquid";
|
7 | 10 | import {
|
@@ -184,7 +187,31 @@ export default function (eleventyConfig: any) {
|
184 | 187 | eleventyConfig.on("eleventy.after", async ({ dir }: EleventyEvent) => {
|
185 | 188 | // addPassthroughCopy can only map each file once,
|
186 | 189 | // but base.css needs to be copied to a 2nd destination
|
187 |
| - await copyFile(`${dir.input}/css/base.css`, `${dir.output}/understanding/base.css`); |
| 190 | + await copyFile( |
| 191 | + join(dir.input, "css", "base.css"), |
| 192 | + join(dir.output, "understanding", "base.css") |
| 193 | + ); |
| 194 | + |
| 195 | + // Output guidelines/index.html and dependencies for PR runs (not for GH Pages or W3C site) |
| 196 | + const sha = process.env.COMMIT_REF; // Read environment variable exposed by Netlify |
| 197 | + if (sha && !process.env.WCAG_MODE) { |
| 198 | + await mkdirp(join(dir.output, "guidelines")); |
| 199 | + await copyFile( |
| 200 | + join(dir.input, "guidelines", "guidelines.css"), |
| 201 | + join(dir.output, "guidelines", "guidelines.css") |
| 202 | + ); |
| 203 | + await copyFile( |
| 204 | + join(dir.input, "guidelines", "relative-luminance.html"), |
| 205 | + join(dir.output, "guidelines", "relative-luminance.html") |
| 206 | + ); |
| 207 | + |
| 208 | + const url = `https://raw.githack.com/${GH_ORG}/${GH_REPO}/${sha}/guidelines/index.html?isPreview=true`; |
| 209 | + const { data: processedGuidelines } = await axios.get( |
| 210 | + `https://labs.w3.org/spec-generator/?type=respec&url=${encodeURIComponent(url)}`, |
| 211 | + { responseType: "text" } |
| 212 | + ); |
| 213 | + await writeFile(`${dir.output}/guidelines/index.html`, processedGuidelines); |
| 214 | + } |
188 | 215 | });
|
189 | 216 |
|
190 | 217 | eleventyConfig.setLibrary(
|
|
0 commit comments