When a content collection has a page in the root (e.g., /collection/index.md), the slug should remain index unless there is a custom slug defined and if the custom slug is empty string (`), it should be treated as a directory reference and resulting url contain a/at end. For subdirectories (e.g.,/collection/subdir/index.md`), index should be stripped.
Found this issue and confirmed behavior that Astro itself does not strip index for root pages in a collection unless custom slug is defined.
Click on Go to Other Stuff Index under Repro for Issue #16
Expected Behavior:
Link should navigate to /otherstuff/index
Actual Behavior:
index is stripped and link results in 404
Go back to Post 1
Hover over (or inspect via dev console) the link for Go to Posts Index
Expected Behavior:
Link should be /posts/ since it contains a custom slug of empty string ('')
Actual Behavior:
Link is /posts without the trailing slash
Additional Info:
1) Clicking on Go to Other Stuff Subdir Index works as index is properly stripped
2) Clicking on Go to Posts Index works but the url is wrong (see step 4 & 5) - The existing code does a boolean compare on slug to determine if a custom slug exists but empty string evaluates to false so its treated as not having a custom slug
3) Clicking on Go to Other Stuff 2 Index works as a custom slug of myindex is defined and it is properly detected and transformed
4) You can see all links that Astro generates on home page under Issue #16 heading
5) Related: Special case handling of index files was added in #3 based on #2
When a content collection has a page in the root (e.g.,
/collection/index.md
), the slug should remainindex
unless there is a custom slug defined and if the custom slug is empty string (`), it should be treated as a directory reference and resulting url contain a
/at end. For subdirectories (e.g.,
/collection/subdir/index.md`), index should be stripped.Found this issue and confirmed behavior that Astro itself does not strip
index
for root pages in a collection unless custom slug is defined.Repro:
With Proposed Fixes from PR #21:
Steps to reproduce:
Post 1
linkGo to Other Stuff Index
underRepro for Issue #16
Expected Behavior: Link should navigate to
/otherstuff/index
Actual Behavior:
index
is stripped and link results in 404Post 1
Go to Posts Index
Expected Behavior: Link should be
/posts/
since it contains a custom slug of empty string (''
)Actual Behavior: Link is
/posts
without the trailing slashAdditional Info: 1) Clicking on
Go to Other Stuff Subdir Index
works asindex
is properly stripped 2) Clicking onGo to Posts Index
works but the url is wrong (see step 4 & 5) - The existing code does a boolean compare on slug to determine if a custom slug exists but empty string evaluates to false so its treated as not having a custom slug 3) Clicking onGo to Other Stuff 2 Index
works as a custom slug ofmyindex
is defined and it is properly detected and transformed 4) You can see all links that Astro generates on home page underIssue #16
heading 5) Related: Special case handling ofindex
files was added in #3 based on #2