From 8bafaefc24fdbd76a376983f56472eae9d574f0d Mon Sep 17 00:00:00 2001 From: Alexandre Capt Date: Tue, 12 Jun 2018 12:17:02 +0200 Subject: [PATCH 1/2] Integrated nav from SUMMARY.md --- src/default.htl | 14 +------------- src/default.pre.js | 28 ++++++++++++++++++++++++++++ src/dist/styles.css | 22 ++++++++++++++++++---- 3 files changed, 47 insertions(+), 17 deletions(-) diff --git a/src/default.htl b/src/default.htl index e2a4397..2e7f956 100644 --- a/src/default.htl +++ b/src/default.htl @@ -12,19 +12,7 @@
diff --git a/src/default.pre.js b/src/default.pre.js index eba5441..4d99ca8 100644 --- a/src/default.pre.js +++ b/src/default.pre.js @@ -1,5 +1,6 @@ const moment = require('moment'); const request = require('request-promise'); +const md2json = require('md2json'); /** * Removes the first title from the resource children @@ -34,6 +35,32 @@ function collectMetadata(ctx) { }); }; +/** + * Collects the nav and append it to the resource + * @param {RequestContext} ctx Context + */ +function collectNav(ctx) { + const params = { + org: ctx.strandConfig.content.org, + repo: ctx.strandConfig.content.repo, + tree: ctx.strandConfig.content.tree, + 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.strand + '/'); + }); + return Promise.resolve(ctx); + }); +}; + /** * Extracts some committers data from the list of commits and appends the list to the resource * @param {RequestContext} ctx Context @@ -80,6 +107,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); }); diff --git a/src/dist/styles.css b/src/dist/styles.css index 7babaa5..61f8d9a 100644 --- a/src/dist/styles.css +++ b/src/dist/styles.css @@ -57,19 +57,33 @@ h1 { color: #aaa; } +.nav ul li ul a { + list-style: none; + color: #aaa; +} -.nav ul li.open { +.nav a { + text-decoration: none; + color: inherit; +} + +.nav ul li.open, .nav ul li.open a { list-style-image: url('data:image/svg+xml;utf8,'); } -.nav ul li.selected { +.nav ul li.selected, .nav ul li.selected a { color: #e00; } -.nav ul li { +.nav ul li, .nav ul li a { padding-top: 5px; padding-bottom: 5px; - +} + +.nav ul li p { + font-size: 16px; + line-height: 1.5em; + margin: 0; } .content { From b342f4d6fb8777e855ffd354bfee792ba2927192 Mon Sep 17 00:00:00 2001 From: Alexandre Capt Date: Tue, 12 Jun 2018 16:26:26 +0200 Subject: [PATCH 2/2] Aligned with StrandConfig object --- src/default.pre.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/default.pre.js b/src/default.pre.js index 4d99ca8..275f3bb 100644 --- a/src/default.pre.js +++ b/src/default.pre.js @@ -18,7 +18,9 @@ function removeFirstTitle(ctx) { function collectMetadata(ctx) { const options = { uri: - ctx.strandConfig.content.api + + ctx.strandConfig.urls.content.apiRoot + + '/repos/' + + ctx.strandConfig.urls.content.repo + '/commits?path=' + ctx.resourcePath + '.md', @@ -41,9 +43,9 @@ function collectMetadata(ctx) { */ function collectNav(ctx) { const params = { - org: ctx.strandConfig.content.org, - repo: ctx.strandConfig.content.repo, - tree: ctx.strandConfig.content.tree, + org: ctx.strandConfig.urls.content.owner, + repo: ctx.strandConfig.urls.content.name, + tree: ctx.strandConfig.urls.content.ref, path: 'SUMMARY.md' };