i have copied the content of the folder 'test/mocks' to a new node project under 'src'.
const Metalsmith = require('metalsmith'),
xhandlebars = require('metalsmith-handlebars-x'),
Handlebars = require('handlebars'),
layouts = require('metalsmith-layouts'),
discover = require('metalsmith-discover-partials');
// Handlebars.registerHelper(require('handlebars-layouts')(Handlebars));
Metalsmith(__dirname)
.source('./src')
.destination('./dist')
.clean(true)
.use(discover({
directory: './partials'
}))
.use(layouts({
directory: './partials',
pattern: '**/test.hbs',
suppressNoFilesError: true
}))
.ignore('**/handlebars-layouts*')
.use(xhandlebars({
instance: Handlebars,
pattern: '**/*.{hbs}',
layout: true,
partials: 'partials',
helpers: {},
}))
.process(function(err, result) {
if (err) throw err;
Object.keys(result).forEach((prop) => {
console.log(prop);
console.log(result[prop].contents.toString());
console.log();
});
});
{
"name": "metal-test",
"version": "1.0.0",
"description": "test metalsmith",
"main": "metalsmith.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"devDependencies": {
"handlebars": "^4.7.6",
"handlebars-layouts": "^3.1.4",
"metalsmith": "^2.3.0",
"metalsmith-discover-partials": "^0.1.2",
"metalsmith-handlebars-x": "^0.2.2",
"metalsmith-layouts": "^2.3.1"
},
"dependencies": {}
}
test.hbs
{{>include}}
posts/test.hbs
{{>include}}
I can't figure out what i'm doing wrong.