From a034bcdc019ed2bdbac3753c31905285d03aadbf Mon Sep 17 00:00:00 2001 From: Matt J Cloyd Date: Mon, 10 Jun 2024 16:54:23 -0400 Subject: [PATCH] Fix truncated asset path strings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit There was an issue where asset names were getting truncated by a one character, but it was caused by extra unnecessary files getting ingested into the asset build. This commit: - Adds to buildAssets.js an error throw, when the conditions for the truncation exist. - Removes the file that has been the main culprit — a README.md in the blog assets which 11ty thought was a .md file to be rendered into HTML. Fixes #3859 --- assets/blog/README.md | 7 ------- config/buildAssets.js | 3 +++ 2 files changed, 3 insertions(+), 7 deletions(-) delete mode 100644 assets/blog/README.md diff --git a/assets/blog/README.md b/assets/blog/README.md deleted file mode 100644 index f5dad1fd9..000000000 --- a/assets/blog/README.md +++ /dev/null @@ -1,7 +0,0 @@ -## No images here - -Don't put images or other assets directly in this directory! Always make a new directory per-post, like those above, to store assets. - -The directory doesn't have to use the same slug as your post. Just pick something that doesn't exist yet, and use it. - -Thank you for doing your part in keeping a Clean Blog For All. diff --git a/config/buildAssets.js b/config/buildAssets.js index 05b5c8cfb..ed3ce20e7 100644 --- a/config/buildAssets.js +++ b/config/buildAssets.js @@ -45,6 +45,9 @@ async function createAssetPaths() { file.indexOf(publicDir) + publicDir.length, ); const hashedAt = name.lastIndexOf('-'); + if (hashedAt === -1) { + throw new Error(`hashedAt is -1, which is an error likely caused by a stray file (${file}) being pulled into the assets build path`) + } const originalName = name.slice(0, hashedAt); const key = `${originalName}${ext}`; return {