From 840f73d73939eaaa7282e982572e8fbc496ae3a0 Mon Sep 17 00:00:00 2001 From: Roman Axelrod Date: Tue, 15 Nov 2022 16:33:22 +0200 Subject: [PATCH] Fix handlebars path issue on Windows OS. --- server.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/server.js b/server.js index b3a15e8..1e8d8f4 100755 --- a/server.js +++ b/server.js @@ -77,7 +77,7 @@ app.get('/', async (req, res) => { data.helpers = { port, - include_partial: (filesPath) => path.join(modulesPath, filesPath), + include_partial: (filesPath) => handlebarLayoutsPath(modulesPath, filesPath), baseView, previewFrameUrl: `${previewFrameUrl}/${baseViewUrl}`, } @@ -95,8 +95,8 @@ app.get('/view/:baseView', async (req, res) => { const blockName = config.has('blockName') ? config.get('blockName') : developmentBlockName; data.helpers = { - include_partial: (filesPath) => path.join(modulesPath, filesPath), - include_block_template: () => path.join(projectPath, 'src', `${blockName}.template`), + include_partial: (filesPath) => handlebarLayoutsPath(modulesPath, filesPath), + include_block_template: () => handlebarLayoutsPath(projectPath, 'src', `${blockName}.template`), section_class: `${blockName}--${jsonFileName}`, base_url: '/' } @@ -396,3 +396,8 @@ function handleSyntaxErrors(err, req, res, next) { next(); } + +function handlebarLayoutsPath() { + return path.join(...arguments) + .replace(/\\/g, '/'); // Windows path issue. Fix all "\" for Handlebars. +} -- 2.30.2