From 532dd30205430317a4b3216c0458c3263128a1b3 Mon Sep 17 00:00:00 2001 From: Rickard Falk Date: Thu, 25 Jan 2024 14:09:21 +0100 Subject: [PATCH 1/2] feat: add handlebar helper prefixModuleScript --- README.md | 1 + lib/handlebars/helpers/headerContent.js | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/README.md b/README.md index 3019cba..2b0047d 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,7 @@ registerHeaderContentHelper({ - {{ extend name options }} -- calls the function options.fn with content of block **name** as param and adds it to named block - {{ prefixScript url name }} -- add a script tag with version set to script block **name** +- {{ prefixModuleScript url name }} -- add a script tag with type module and with version set to script block **name** - {{ prefixStyle url name media }} -- add a style tag for named media type with version set to style block **name** - {{ render name }} -- used by a layout to render script and style blocks in appropriate places - {{ withVersion url }} -- appends `'?v=' + version` to the passed string diff --git a/lib/handlebars/helpers/headerContent.js b/lib/handlebars/helpers/headerContent.js index 64fe295..35d5b7d 100644 --- a/lib/handlebars/helpers/headerContent.js +++ b/lib/handlebars/helpers/headerContent.js @@ -87,6 +87,30 @@ module.exports = function headerContent(options) { _blocks[blockName].push(``) }) + /** @function prefixModuleScript + * + * @param {string} url -- local path to script excluding proxyPrefixPath + * @param {string} blockName -- (optional) name of script block to include with, defaults to 'scripts' + * + * @return output with {{ render blockName }} + * + * @example + * {{prefixModuleScript '/path/to/script.js' 'scripts'}} + */ + Handlebars.registerHelper('prefixModuleScript', function prefixModuleScript(urlIn, blockNameIn) { + // Check params and give useful error message since stack traces aren't very useable in layouts + if (typeof urlIn !== 'string') { + throw new Error('[prefixModuleScript] helper requires first parameter (url) to be a string. Got: ' + urlIn) + } + + const blockName = typeof blockNameIn === 'string' ? blockNameIn : 'scripts' + _blocks[blockName] = _blocks[blockName] || [] + + const url = `${proxyPrefixPathUri}${urlIn}?v=${encodeURIComponent(version)}` + + _blocks[blockName].push(``) + }) + /** @function prefixStyle * * @param {string} url -- local path to script excluding proxyPrefixPath From 192fbec9043bb9ee4b42e9cb04f227c9523a2d52 Mon Sep 17 00:00:00 2001 From: Pipeline Date: Thu, 25 Jan 2024 13:17:44 +0000 Subject: [PATCH 2/2] 9.0.3-0 --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 75bfa14..c49aa49 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@kth/kth-node-web-common", - "version": "9.0.2", + "version": "9.0.3-0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@kth/kth-node-web-common", - "version": "9.0.2", + "version": "9.0.3-0", "license": "MIT", "dependencies": { "@kth/cortina-block": "^5.1.1", diff --git a/package.json b/package.json index 26f7825..d7b6be0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@kth/kth-node-web-common", - "version": "9.0.2", + "version": "9.0.3-0", "description": "Common components for node-web projects", "scripts": { "test": "jest",