vernak2539 / astro-rehype-relative-markdown-links

Rehype Plugin for Astro that allows for usage of relative links between markdown files
https://www.npmjs.com/package/astro-rehype-relative-markdown-links
15 stars 4 forks source link

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

Closed techfg closed 7 months ago

techfg commented 7 months ago

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 #3 based on #2

techfg commented 7 months ago

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

vernak2539 commented 7 months ago

Released in v0.9.0! Thanks!