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
12 stars 4 forks source link

bug: inconsistent application of forward slash for collection index pages #54

Closed techfg closed 5 months ago

techfg commented 5 months ago

When transforming index.md urls within a content collection, the transforming is inconsistent between index.md in the collection root and index.md in collection subdirectories.

For example, ./src/content/docs/index.md with a custom slug of '' will transform to /docs/ (includes /) whereas ./src/content/docs/child/index.md will transform to /docs/child (doesn't include /).

In PR #20, trailingSlash support was added and it forced a '/' when the custom slug is empty string (''). This behavior is correct when the collection is acting as the site root (collectionPathMode='root') but when the collection is not in the site root, a trailingSlash should not be forced and defer to the trailingSlash setting.

Repro: https://stackblitz.com/edit/withastro-astro-l1egoq

Steps to reproduce:

  1. Navigate to https://stackblitz.com/edit/withastro-astro-l1egoq
  2. Click on Docs Index link to enter into the collection index page
  3. Hover over (or inspect in dev tools) the links generated for Docs Index, Docs Child Index and Docs Grandchild Index

Expected Result: The same behavior should be applied to all links - none of them should end in trailing slash

Actual Result: The behavior is different for Docs Index which ends in a trailing slash compared to Docs Child Index & Docs Grandchild Index which do not end in a trailing slash

Additional Information

The current behavior of forcing a forward slash / in the generated URL for the collection root itself should still remain when the collectionPathMode='root' (e.g., the docs/index.md url should transform to / and for docs/child/index.md and docs/child/grandchild/index.md there should be no trailing slash, /child and /child/grandchild respectively).