stereobooster / react-snap

👻 Zero-configuration framework-agnostic static prerendering for SPAs
MIT License
5.06k stars 394 forks source link

Support relative links #401

Open jonathantneal opened 5 years ago

jonathantneal commented 5 years ago

Description

This change allows react-snap to write relative links to href and src attributes. It addresses the request in #397, and by happenstance resolves #153.

It accomplishes this by:

  1. Detecting the desire for relative links by checking options.publicPath for a leading dot (.) or explicitly using options.useRelativeLinks.
  2. Rewriting the public path using url.URL to avoid adding more RegExp logic (url.URL is used over the URL global for Node 8+ compatibility). This part happenstance resolves #153.
  3. When relative links are enabled, it traverses elements with [href^="/"], [href^="./"], [src^="/"], and [src^="./"], and replaces it with closest relative version.
jareware commented 5 years ago

Very much looking forward to this!

joeyschroeder commented 5 years ago

This looks great! Looking forward to this too. 👍

loganpowell commented 4 years ago

Is this going out?