Skip to content

Commit

Permalink
fix: match index files only by using entire basename
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ericswpark committed Dec 23, 2024
1 parent 98f9e83 commit 491e4d2
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion packages/astro/src/core/routing/manifest/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 491e4d2

Please sign in to comment.