Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: Incorrectly strips index from content collection root index page #16

Closed
techfg opened this issue Apr 7, 2024 · 2 comments · Fixed by #17
Closed

bug: Incorrectly strips index from content collection root index page #16

techfg opened this issue Apr 7, 2024 · 2 comments · Fixed by #17

Comments

@techfg
Copy link
Contributor

techfg commented Apr 7, 2024

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.

Repro:

With Proposed Fixes from PR #21:

Steps to reproduce:

  1. Open repro
  2. Click on Post 1 link
  3. 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

  1. Go back to Post 1
  2. 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 Process index.md files correctly + add contentPath option #3 based on Does not work with index pages #2
techfg added a commit to techfg/astro-rehype-relative-markdown-links that referenced this issue Apr 7, 2024
techfg added a commit to techfg/astro-rehype-relative-markdown-links that referenced this issue Apr 7, 2024
@techfg
Copy link
Contributor Author

techfg commented Apr 10, 2024

FYI - Edited OP to a Stackblitz to the repro that contains the proposed fixes from #21.

@vernak2539
Copy link
Owner

Released in v0.9.0! Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants