Rewrites absolute URLs to relative ones with remark
I created this plugin to use in tandem with remark-external-links so that any links that content creators have used absolute versions of can be corrected before that plugin's logic takes effect.
Use this before gatsby-remark-external-links
yarn add gatsby-remark-relative-links
Add following to your gatsby-config.js
:
plugins: [
{
resolve: `gatsby-transformer-remark`,
options: {
plugins: [
{
resolve: "gatsby-remark-relative-links",
options: {
domainRegex: /http[s]*:\/\/[www.]*yoursite\.com[/]?/,
}
},
'gatsby-remark-external-links',
]
}
},
Type: string
Default: null
Regex used to decipher what domain to "relative-ize". The example provided should handle most cases.