Skip to content

Commit ca7d938

Browse files
authored
Print tip about restarting dev server for certain cases (#4535)
This provides guidance within terminal output when running the dev server, to notify users that the server can be restarted, and should be for certain editing cases. Other fixes in this PR: - Fix formatting elsewhere in `eleventy.config.ts` (this has been bugging me for a while, but I didn't want to cram it into any bigger PRs and risk making them more confusing) - Constrain `eleventyignore` line for `img` folders to only ignore `*.html`, so changes to images no longer require a dev server restart (this does not cause any build changes)
1 parent 8115cde commit ca7d938

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

.eleventyignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@ understanding/*/seizures.html
2323
**/*-template.html
2424

2525
# HTML files under img will be passthrough-copied
26-
**/img/*
26+
**/img/*.html

eleventy.config.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,8 @@ export default async function (eleventyConfig: any) {
254254
if (runMode === "build" && process.env.WCAG_MODE === "publication") await rimraf("_site");
255255
});
256256

257-
eleventyConfig.on("eleventy.after", async ({ dir }: EleventyEvent) => {
257+
let hasDisplayedGuidance = false;
258+
eleventyConfig.on("eleventy.after", async ({ dir, runMode }: EleventyEvent) => {
258259
// addPassthroughCopy can only map each file once,
259260
// but base.css needs to be copied to a 2nd destination
260261
await copyFile(
@@ -289,6 +290,13 @@ export default async function (eleventyConfig: any) {
289290
assertIsWcagVersion(version);
290291
await writeFile(`${dir.output}/wcag.json`, await generateWcagJson(version));
291292
}
293+
294+
if (runMode === "serve" && !hasDisplayedGuidance) {
295+
hasDisplayedGuidance = true;
296+
console.log(
297+
"The dev server will restart on TypeScript changes. If you are adding new HTML pages, press Enter to restart it manually."
298+
);
299+
}
292300
});
293301

294302
eleventyConfig.setLibrary(
@@ -408,13 +416,11 @@ export default async function (eleventyConfig: any) {
408416
eleventyConfig.addShortcode("gh", (id: string) => {
409417
if (/^#\d+$/.test(id)) {
410418
const num = id.slice(1);
411-
return `<a href="https://github.com/${GH_ORG}/${GH_REPO}/pull/${num}" aria-label="pull request ${num}">${id}</a>`
412-
}
413-
else if (/^[0-9a-f]{7,}$/.test(id)) {
419+
return `<a href="https://github.com/${GH_ORG}/${GH_REPO}/pull/${num}" aria-label="pull request ${num}">${id}</a>`;
420+
} else if (/^[0-9a-f]{7,}$/.test(id)) {
414421
const sha = id.slice(0, 7); // Truncate in case full SHA was passed
415-
return `<a href="https://github.com/${GH_ORG}/${GH_REPO}/commit/${sha}" aria-label="commit ${sha}">${sha}</a>`
416-
}
417-
else throw new Error(`Invalid SHA or PR ID passed to gh tag: ${id}`);
422+
return `<a href="https://github.com/${GH_ORG}/${GH_REPO}/commit/${sha}" aria-label="commit ${sha}">${sha}</a>`;
423+
} else throw new Error(`Invalid SHA or PR ID passed to gh tag: ${id}`);
418424
});
419425

420426
// Renders a section box (used for About this Technique and Guideline / SC)

0 commit comments

Comments
 (0)