From 01f11f6fcf749a5ee740c46b86a010ccc2d2b861 Mon Sep 17 00:00:00 2001 From: Dan Allen Date: Wed, 18 Mar 2020 16:02:54 -0600 Subject: [PATCH] register built-in helpers (resolvePage and resolvePageURL) with stub implementation in preview site --- gulp.d/tasks/build-preview-pages.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/gulp.d/tasks/build-preview-pages.js b/gulp.d/tasks/build-preview-pages.js index 74d61ae..91cb1e9 100644 --- a/gulp.d/tasks/build-preview-pages.js +++ b/gulp.d/tasks/build-preview-pages.js @@ -79,6 +79,8 @@ function registerPartials (src) { } function registerHelpers (src) { + handlebars.registerHelper('resolvePage', resolvePage) + handlebars.registerHelper('resolvePageURL', resolvePageURL) return vfs.src('helpers/*.js', { base: src, cwd: src }).pipe( map((file, enc, next) => { handlebars.registerHelper(file.stem, requireFromString(file.contents.toString())) @@ -100,6 +102,14 @@ function copyImages (src, dest) { return vfs.src('**/*.{png,svg}', { base: src, cwd: src }).pipe(vfs.dest(dest)) } +function resolvePage (spec, context = {}) { + if (spec) return { pub: { url: resolvePageURL(spec) } } +} + +function resolvePageURL (spec, context = {}) { + if (spec) return '/' + (spec = spec.split(':').pop()).slice(0, spec.lastIndexOf('.')) + '.html' +} + function toPromise (stream) { return new Promise((resolve, reject) => stream.on('error', reject).on('finish', resolve)) } -- 2.11.0