Gatsby rehype plugin that rewrites URLs of src/href attributes.
yarn add gatsby-transformer-rehype @suin/gatsby-rehype-replace-urls
// In your gatsby-config.js
module.exports = {
plugins: [
{
resolve: `gatsby-transformer-rehype`,
options: {
plugins: [
{
resolve: '@suin/gatsby-rehype-replace-urls',
options: {
replace({ url }) {
const u = new URL(url)
if (u.protocol === 'http:') {
u.protocol = 'https'
}
return u
},
},
},
],
},
},
]
}
replace
function, see API doc.Generated using TypeDoc