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

feat: add trailingSlash support (#11) #20

Closed techfg closed 6 months ago

techfg commented 6 months ago

Resolves #11

I based this PR off of PR #17 as it made solutioning for supporting trailingSlash more straightforward to resolve than the prior code base would have (e.g., several issues in resolving the final url would have required several more modifications to the code than what is contained in this PR). If the decision is made to not merge #17, I can make the modifications to this one based on existing code but hopefully you'll agree #17 is worth merging :)

Regarding supporting the trailingSlash option, I spent some time reviewing what other Astro packages are doing around trailingSlash support since there isn't any official documentation on how trailingSlash is supposed to work because from an core Astro perspective, it's really only a dev server config flag in terms of how it responds to requests. Integrations, etc. have utilized it to offer rendering support in urls but its somewhat mixed in terms of how always, never and ignore are applied. With that said, the approach I landed on is as follows:

  1. always - Will ensure any transformed url always contains a trailing slash regardless of file path or custom slug
  2. never - Will ensure any transformed url never contains a trailing slash regardless of file path or custom slug
  3. ignore - Will ensure any transformed url remains identical trailing slash wise to the input of either the file path or custom slug (whichever was used).

always and never are straightforward but ignore warrants an example. Assuming pages of post-1.md and post-2.md in the root folder of a content collection blog, the following would be produced from the markdown of page-1.md:

In short, ignore is controlled by what's in the input and provides a way to include a trailing slash when desired regardless of whether or not the file path was resolved or a custom slug was provided.

Open to any feedback/suggestions, thank you!

vernak2539 commented 6 months ago

Hey! There's been a lot of changes since this PR was opened, causing conflicts in the file. I did end up updating the tests, which, IMO, are much better and grouped a bit more consistently around functionality. Happy to review this when ready, as I think it would be beneficial functionality!

techfg commented 6 months ago

Yep, working on the merge now, was waiting till #17 merged :)

techfg commented 6 months ago

@vernak2539 - Merged! FYI, saw your ternary change from the last PR and made another small tweak to use a const value for the set & compare, hope you don't mind :)