Skip to content

Commit

Permalink
Fix handlebars bug
Browse files Browse the repository at this point in the history
  • Loading branch information
bcomnes committed Nov 24, 2023
1 parent 0a36da4 commit 76cfee1
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/build-pages/page-builders/html/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export async function htmlBuilder ({ pageInfo }) {
vars: {},
pageLayout: async (vars) => {
// @ts-ignore
if (vars?.handlebars) {
if (vars?.vars?.handlebars) {
const template = Handlebars.compile(fileContents)
return template(vars)
} else {
Expand Down
2 changes: 1 addition & 1 deletion lib/build-pages/page-builders/md/get-md.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export function getMd () {
export function renderMd (mdUnparsed, vars, md) {
if (!md) md = getMd()
// @ts-ignore
if (vars?.handlebars) {
if (vars?.vars?.handlebars) {
const template = Handlebars.compile(mdUnparsed)
const body = rewriteLinks(md.render(template(vars)))
return body
Expand Down
2 changes: 1 addition & 1 deletion lib/identify-pages.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ tap.test('identifyPages works as expected', async (t) => {
t.ok(results.layouts, 'Layouts are found')
// eslint-disable-next-line dot-notation
t.ok(results.layouts['root'], 'A root layouts is found')
t.equal(Object.keys(results.pages).length, 18, '18 pages are found')
t.equal(Object.keys(results.pages).length, 22, '22 pages are found')

t.equal(results.warnings.length, 0, '0 warnings produced')
// t.equal(results.nonPageFolders.length, 4, '4 non-page-folder')
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

<h1>A page with some disabled handlebars</h1>

<p>Here is a rendered handlebars template {{ vars.handlebars }}</p>
<p>Here is an escaped handlebars template \{{ vars.handlebars }}</p>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default {
handlebars: false
}
5 changes: 5 additions & 0 deletions test-cases/general-features/src/handlebars-html/page.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

<h1>A page with some handlebars</h1>

<p>Here is a rendered handlebars template {{ vars.someVar }}</p>
<p>Here is an escaped handlebars template \{{ vars.someVar }}</p>
3 changes: 3 additions & 0 deletions test-cases/general-features/src/handlebars-html/page.vars.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default {
someVar: 'value of the var'
}
7 changes: 7 additions & 0 deletions test-cases/general-features/src/handlebars-md/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
someVar: 'value of the var'
---
# A page with some handlebars

Here is a rendered handlebars template {{ vars.someVar }}
Here is an escaped handlebars template \{{ vars.someVar }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
handlebars: false
---
# Disabled handlebars template

Here is a handlebars template that should not be rendered: {{ vars.handlebars }}
Here is an escaped handlebars template that should not be rendered: \{{ vars.handlebars }}

0 comments on commit 76cfee1

Please sign in to comment.