From 81e6b39c2fefb5f3fb78ed22e7e765aee611d663 Mon Sep 17 00:00:00 2001 From: Dan Allen Date: Sat, 24 Aug 2019 03:54:58 -0600 Subject: [PATCH] make current page URL argument to relativize helper optional --- src/helpers/relativize.js | 14 ++++++++++++-- src/partials/breadcrumbs.hbs | 4 ++-- src/partials/nav-explore.hbs | 2 +- src/partials/nav-menu.hbs | 2 +- src/partials/nav-tree.hbs | 2 +- src/partials/page-versions.hbs | 2 +- src/partials/toolbar.hbs | 2 +- 7 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/helpers/relativize.js b/src/helpers/relativize.js index 090ee24..950703a 100644 --- a/src/helpers/relativize.js +++ b/src/helpers/relativize.js @@ -2,8 +2,16 @@ const { posix: path } = require('path') -// TODO memoize -module.exports = (from, to) => { +// TODO memoize me +function relativize (to, ctx) { + let from + // legacy invocation + if (arguments.length > 2) { + [from, to, ctx] = arguments + } else { + from = ctx.data.root.page.url + } + if (!to) return '#' if (!from || to.charAt() === '#') return to let hash = '' const hashIdx = to.indexOf('#') @@ -21,3 +29,5 @@ module.exports = (from, to) => { function isDir (str) { return str.charAt(str.length - 1) === '/' } + +module.exports = relativize diff --git a/src/partials/breadcrumbs.hbs b/src/partials/breadcrumbs.hbs index 503772e..d2ce9e3 100644 --- a/src/partials/breadcrumbs.hbs +++ b/src/partials/breadcrumbs.hbs @@ -3,13 +3,13 @@ diff --git a/src/partials/nav-menu.hbs b/src/partials/nav-menu.hbs index 27a667d..042f167 100644 --- a/src/partials/nav-menu.hbs +++ b/src/partials/nav-menu.hbs @@ -1,7 +1,7 @@ {{#if page.navigation}} diff --git a/src/partials/nav-tree.hbs b/src/partials/nav-tree.hbs index 837fbf8..f0576bd 100644 --- a/src/partials/nav-tree.hbs +++ b/src/partials/nav-tree.hbs @@ -8,7 +8,7 @@ {{/if}} {{#if ./url}} {{{./content}}} {{else}} {{{./content}}} diff --git a/src/partials/page-versions.hbs b/src/partials/page-versions.hbs index 321635c..c6c3f05 100644 --- a/src/partials/page-versions.hbs +++ b/src/partials/page-versions.hbs @@ -5,7 +5,7 @@ {{#each page.versions}} {{./displayVersion}} + {{~#if ./missing}} is-missing{{/if}}" href="{{{relativize ./url}}}">{{./displayVersion}} {{/each}} diff --git a/src/partials/toolbar.hbs b/src/partials/toolbar.hbs index 243ab80..251a51a 100644 --- a/src/partials/toolbar.hbs +++ b/src/partials/toolbar.hbs @@ -1,7 +1,7 @@