Skip to content

Commit

Permalink
plugin to parse {{root_url}} for links and imr src
Browse files Browse the repository at this point in the history
  • Loading branch information
justinwhall committed Jul 24, 2018
1 parent 782e48f commit 67d25c3
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions gatsby-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ module.exports = {
resolve: 'gatsby-transformer-remark',
options: {
plugins: [
'sendgrid-remark-paths',
{
resolve: 'gatsby-remark-images',
options: {
Expand Down
27 changes: 27 additions & 0 deletions plugins/sendgrid-remark-paths/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const visit = require('unist-util-visit');

module.exports = ({ markdownAST, pathPrefix }) => {
const uriPrefix = pathPrefix.length ? pathPrefix : '';

// Replace {{root_url}} for all links
visit(markdownAST, 'link', (node) => {
if (
node.url &&
node.url.startsWith('{{root_url}}')
) {
node.url = node.url.replace('{{root_url}}', uriPrefix);
}
});

// Replace {{root_url}} for all imags
visit(markdownAST, 'image', (node) => {
if (
node.url &&
node.url.startsWith('{{root_url}}')
) {
node.url = node.url.replace('{{root_url}}', uriPrefix);
}
});

return markdownAST;
};
1 change: 1 addition & 0 deletions plugins/sendgrid-remark-paths/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}

0 comments on commit 67d25c3

Please sign in to comment.