Skip to content
This repository has been archived by the owner on Aug 27, 2019. It is now read-only.

Commit

Permalink
#4: Adding rewrite for navigation links in ESI
Browse files Browse the repository at this point in the history
  • Loading branch information
davidnuescheler committed Jun 20, 2018
1 parent 57cdcd9 commit 3d3af8a
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/nav.pre.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,24 @@ function removeFirstTitle(ctx) {
return Promise.resolve(ctx);
};

/**
* Rewrites links in nav prefixing with strain context changing to .html
* @param {RequestContext} ctx Context
*/
function rewriteLinks(ctx) {
ctx.resource.children = ctx.resource.children.map(element => {
return element.replace(new RegExp('(href=")(.*)(\.md")', 'g'), 'href="/' + ctx.strain + '/$2.html"');
});
return Promise.resolve(ctx);
};

module.exports.main = function (ctx) {
ctx.resource = ctx.resource || {};

return Promise.resolve(ctx)
.then(setContextPath)
.then(removeFirstTitle)
.then(rewriteLinks)
.catch(error => {
console.error('Error while executing nav.pre.js', error);
});
Expand Down

0 comments on commit 3d3af8a

Please sign in to comment.