From 3acc65444c27d87b6f2d61bdfa7df0e0db4e2686 Mon Sep 17 00:00:00 2001 From: Eric Park Date: Mon, 6 Jan 2025 04:57:53 +0900 Subject: [PATCH] fix: match index files only by using entire basename (#12815) * fix: match index files only by using entire basename The previous code would cause file names like `index.xml.ts` to be treated as index files, when they aren't (the file basename excluding the extension `.ts` is `index.xml`, and `index` should be the index file). To match index files only, match the entire first half of the basename when splitting by the last occurrence of the period/file extension delimiter. Pedantically this might not be correct -- i.e. some file extensions actually span multiple delimiters, like index.tar.gz. But in that case it's not an index file as well, so I think this is fine. Fixes #12675 * Add changeset --- .changeset/small-maps-give.md | 5 +++++ packages/astro/src/core/routing/manifest/create.ts | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 .changeset/small-maps-give.md diff --git a/.changeset/small-maps-give.md b/.changeset/small-maps-give.md new file mode 100644 index 0000000000..e62ef3e4ef --- /dev/null +++ b/.changeset/small-maps-give.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Some non-index files that were incorrectly being treated as index files are now excluded diff --git a/packages/astro/src/core/routing/manifest/create.ts b/packages/astro/src/core/routing/manifest/create.ts index d1f498432e..aabdd4e63d 100644 --- a/packages/astro/src/core/routing/manifest/create.ts +++ b/packages/astro/src/core/routing/manifest/create.ts @@ -183,7 +183,7 @@ function createFileBasedRoutes( validateSegment(segment, file); const parts = getParts(segment, file); - const isIndex = isDir ? false : basename.startsWith('index.'); + const isIndex = isDir ? false : basename.substring(0, basename.lastIndexOf('.')) === "index"; const routeSuffix = basename.slice(basename.indexOf('.'), -ext.length); const isPage = validPageExtensions.has(ext);