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: markdown links to files outside of a `content collection directory` should not be transformed #57

Open techfg opened 5 months ago

techfg commented 5 months ago

As mentioned in #26, currently the plugin transforms any relative markdown link in any markdown file (e.g., even if it's in the page directory or in the content directory and points to a location outside of content directory).

The decision outlined in #26 still needs to be made with regards to what situations are officially supported and what expected behavior should be, however currently, the plugin assumes that markdown links (regardless of current file location) reference markdown files within a content collection directory. Given this, any relative link that would otherwise be considered valid, should be further restricted to being a relative location within a content collection directory, either in the same collection or another collection.

Assuming PR #49 is merged (and preferably #50 merged and #53 implemented), cross collection references should be reliable, however references to a location outside of a content collection directory will still not work and are not currently supported given existing behavior.

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

Steps to reproduce:

  1. Navigate to https://stackblitz.com/edit/withastro-astro-xtq8zt
  2. Click on (or inspect via dev tools) the links for Site Index and Site Test Page
  3. Navigate to Docs Index
  4. Click on (or inspect via dev tools) the links for Site Index and Site Test Page

Expected Behavior: Link is not transformed because linked markdown file is located outside of a content collection directory

Actual Behavior: Links are transformed to /pages and /pages/testpage and 404