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:
Detecting the desire for relative links by checking options.publicPath for a leading dot (.) or explicitly using options.useRelativeLinks.
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.
When relative links are enabled, it traverses elements with [href^="/"], [href^="./"], [src^="/"], and [src^="./"], and replaces it with closest relative version.
Description
This change allows react-snap to write relative links to
href
andsrc
attributes. It addresses the request in #397, and by happenstance resolves #153.It accomplishes this by:
options.publicPath
for a leading dot (.
) or explicitly usingoptions.useRelativeLinks
.url.URL
to avoid adding more RegExp logic (url.URL
is used over theURL
global for Node 8+ compatibility). This part happenstance resolves #153.[href^="/"]
,[href^="./"]
,[src^="/"]
, and[src^="./"]
, and replaces it with closest relative version.