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

chore: improve relative link validation #36

Closed techfg closed 5 months ago

techfg commented 6 months ago

Didn't create an issue for this because its technically not a bug/feat/etc., however the current IsValidRelativeLink function does not detect absolute urls since it only uses path.isAbsolute. For example, an href of https://www.foo.com/test.md will return true of path.isAbsolute.

The href won't be transformed in the above case only because when it tries to find the file, the path it attempts will contain https:/www.foo.com/test.md and will fail. So the plugin is doing what its supposed to do (not transform the file), but not in the way we expect it to.

The changes here will detect absolute URLs (in addition to absolute paths) so that we reduce the risk of issues cropping up in the future because of unexpected values in the paths.