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

Commit

Permalink
Revert "Refactor Navigation Include to use ESI"
Browse files Browse the repository at this point in the history
This reverts commit 57cdcd9, reversing
changes made to 0df74b5.
  • Loading branch information
kptdobe committed Jun 25, 2018
1 parent 170bdc1 commit dbbef1e
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 44 deletions.
2 changes: 1 addition & 1 deletion src/default.htl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
</div>
<div class="main">
<div class="nav">
<esi:include src="/${it.contextPath}/SUMMARY.html" />
<div data-sly-test="${it.nav}" data-sly-list="${it.nav}">${item}</div>
</div>
<div class="content">
<div class="content-body">
Expand Down
28 changes: 28 additions & 0 deletions src/default.pre.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const moment = require('moment');
const request = require('request-promise');
const md2json = require('md2json');

/**
* Appends the context path to the resource based on the strain
Expand Down Expand Up @@ -49,6 +50,32 @@ function collectMetadata(ctx) {
});
};

/**
* Collects the nav and append it to the resource
* @param {RequestContext} ctx Context
*/
function collectNav(ctx) {
const params = {
org: ctx.strainConfig.urls.content.owner,
repo: ctx.strainConfig.urls.content.repo,
tree: ctx.strainConfig.urls.content.ref,
path: 'SUMMARY.md'
};

return md2json.main(params).then(info => {
let nav = info.body.children;
// remove first title
delete nav[0];

// link re-writing
// TODO: move into md2json + parameters
ctx.resource.nav = nav.map(element => {
return element.replace(new RegExp('href="', 'g'), 'href="/' + ctx.strain + '/');
});
return Promise.resolve(ctx);
});
};

/**
* Extracts some committers data from the list of commits and appends the list to the resource
* @param {RequestContext} ctx Context
Expand Down Expand Up @@ -96,6 +123,7 @@ module.exports.main = function (ctx) {
.then(collectMetadata)
.then(extractCommittersFromMetadata)
.then(extractLastModifiedFromMetadata)
.then(collectNav)
.catch(error => {
console.error('Error while executing default.pre.js', error);
});
Expand Down
1 change: 0 additions & 1 deletion src/nav.htl

This file was deleted.

42 changes: 0 additions & 42 deletions src/nav.pre.js

This file was deleted.

0 comments on commit dbbef1e

Please sign in to comment.