0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2025-01-06 22:10:10 -05:00

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
This commit is contained in:
Eric Park 2025-01-06 04:57:53 +09:00 committed by GitHub
parent fbac92f8bd
commit 3acc65444c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 6 additions and 1 deletions

View file

@ -0,0 +1,5 @@
---
'astro': patch
---
Some non-index files that were incorrectly being treated as index files are now excluded

View file

@ -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);