From 5815279b732da78548a435a94d69cda4c41f78f2 Mon Sep 17 00:00:00 2001 From: Zach Leatherman Date: Fri, 27 Sep 2024 15:44:58 -0500 Subject: [PATCH] Allow per-template ignores to extensionless error using `eleventyAllowMissingExtension: true` #3399 --- src/TemplateMap.js | 8 ++++++-- test/EleventyTest.js | 16 +++++++++++++++- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/TemplateMap.js b/src/TemplateMap.js index e47e6bb42..dc953fe16 100644 --- a/src/TemplateMap.js +++ b/src/TemplateMap.js @@ -734,14 +734,18 @@ ${permalinks[page.outputPath] } this.#onEachPage((page) => { - if (page.outputPath === false || page.url === false) { + if ( + page.outputPath === false || + page.url === false || + page.data.eleventyAllowMissingExtension + ) { // do nothing (also serverless) } else { if (TemplatePath.getExtension(page.outputPath) === "") { let e = new Error(`The template at '${page.inputPath}' attempted to write to '${page.outputPath}'${page.data.permalink ? ` (via \`permalink\` value: '${page.data.permalink}')` : ""}, which is a target on the file system that does not include a file extension. -You *probably* want to add a \`.html\` file extension to your permalink, so that most hosts will know how to correctly serve this file to web browsers. Without a file extension, this file may not be reliably deployed without additional hosting configuration (it won’t have a mime type) and may also cause local development issues if you later attempt to write to a subdirectory of the same name. +You *probably* want to add a file extension to your permalink so that hosts will know how to correctly serve this file to web browsers. Without a file extension, this file may not be reliably deployed without additional hosting configuration (it won’t have a mime type) and may also cause local development issues if you later attempt to write to a subdirectory of the same name. Learn more: https://www.zachleat.com/web/trailing-slash/ diff --git a/test/EleventyTest.js b/test/EleventyTest.js index 0863a6542..4c1518fe3 100644 --- a/test/EleventyTest.js +++ b/test/EleventyTest.js @@ -1546,7 +1546,7 @@ test("Truthy outputPath without a file extension now throws an error, issue #339 // The `set*Directory` configuration API methods are not yet allowed in plugins. message: `The template at './test/stubs-virtual/index.html' attempted to write to './_site/foo' (via \`permalink\` value: 'foo'), which is a target on the file system that does not include a file extension. -You *probably* want to add a \`.html\` file extension to your permalink, so that most hosts will know how to correctly serve this file to web browsers. Without a file extension, this file may not be reliably deployed without additional hosting configuration (it won’t have a mime type) and may also cause local development issues if you later attempt to write to a subdirectory of the same name. +You *probably* want to add a file extension to your permalink so that hosts will know how to correctly serve this file to web browsers. Without a file extension, this file may not be reliably deployed without additional hosting configuration (it won’t have a mime type) and may also cause local development issues if you later attempt to write to a subdirectory of the same name. Learn more: https://www.zachleat.com/web/trailing-slash/ @@ -1554,6 +1554,20 @@ This is usually but not *always* an error so if you’d like to disable this err }); }); +test("Truthy outputPath without a file extension can be ignored, issue #3399", async (t) => { + let elev = new Eleventy("./test/stubs-virtual/", undefined, { + config: function (eleventyConfig) { + // eleventyConfig.configureErrorReporting({ allowMissingExtensions: true }); + eleventyConfig.addTemplate("index.html", "", { permalink: "foo", eleventyAllowMissingExtension: true }) + }, + }); + elev.disableLogger(); + + let results = await elev.toJSON(); + t.is(results.length, 1); + t.is(results[0].url, "/foo"); +}); + test("Truthy outputPath without a file extension error message is disabled, issue #3399", async (t) => { let elev = new Eleventy("./test/stubs-virtual/", undefined, { config: function (eleventyConfig) {