Skip to content

Commit baf2b9c

Browse files
committed
fix: support Handlebars partial name containing dot, #179
1 parent b5a0730 commit baf2b9c

File tree

6 files changed

+15
-6
lines changed

6 files changed

+15
-6
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
## 4.20.8 (2025-07-01)
4+
5+
- fix: support Handlebars partial name containing dot, #179
6+
e.g: `schema.org/rating`
7+
38
## 4.20.7 (2025-06-30)
49

510
- fix: support Handlebars helpers defined as object methods to prevent build failure, #177

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "html-bundler-webpack-plugin",
3-
"version": "4.20.7",
3+
"version": "4.20.8",
44
"description": "Generates complete single-page or multi-page website from source assets. Built-in support for Markdown, Eta, EJS, Handlebars, Nunjucks, Pug. Alternative to html-webpack-plugin.",
55
"keywords": [
66
"html",

src/Loader/Preprocessors/Handlebars/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const path = require('path');
22
const LoaderFactory = require('../../LoaderFactory');
3-
const { stringifyJSON, stringifyFn } = require('../../Utils');
3+
const { normalizeVarName, stringifyJSON, stringifyFn } = require('../../Utils');
44
const { loadModule, readDirRecursiveSync } = require('../../../Common/FileUtils');
55
const { isWin, pathToPosix } = require('../../../Common/Helpers');
66

@@ -238,8 +238,8 @@ const preprocessor = (loaderContext, options) => {
238238
throw new Error(message + '\n' + error.toString());
239239
}
240240

241-
// normalize the name to variable-safe name
242-
const varName = 'partial_' + name.replace(/[\/-]/g, '_');
241+
// normalize the partial name to a safe JavaScript variable name
242+
const varName = 'partial_' + name.replace(/[^a-zA-Z0-9_]/g, '_');
243243

244244
precompiledPartials += `
245245
var ${varName} = ${compiled};

test/cases/_preprocessor/js-tmpl-hbs-partials-in-hbs-js/expected/app.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
{{!-- the partial (name containing '/') used in both a Handlebars template and a JS template --}}
1+
{{!-- the partial name containing '/', used in both a Handlebars template and a JS template --}}
22
{{> 'header/subheader' subheaderTitle="this partial used in JS-template !!"}}
3+
{{!-- the partial name contains dot --}}
4+
The rating: {{> schema.org/rating rating="5"}} points.
35
{{!-- the partial will be compiled with variables defined in JS --}}
46
{{> person}}
57
{{!-- the partial will be compiled with the local variables --}}
68
{{> person name="Jerry" age="30"}}
79
{{!-- the partial contains resolved image --}}
810
{{> star}}
11+
912
{{!-- TODO: implement loading helpers in runtime: {{include 'src/markdown.md'}} --}}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<span class="rating">{{rating}}/10</span>

0 commit comments

Comments
 (0)