I tried to get layouts working following the docs and this example and I can't get layouts to work. I saw that in a github post that I needed to also install jstransformers (which I did) and the handlebars version as well.
The layout docs give an example of how to do it with the CLI but I can't see where I'm going wrong. I have tried a variety of options for layouts, including leaving them blank, but nothing seems to work.
Build.js
var metalsmith = require('metalsmith');
var markdown = require('metalsmith-markdown');
var layouts = require('metalsmith-layouts');
var handlebars = require('handlebars');
var jstransformer = require('metalsmith-jstransformer');
var handlebars = require('jstransformer')(require('jstransformer-handlebars'));
metalsmith(__dirname)
.metadata({
site: {
name: 'Electroniq',
description: 'Test site with Metalsmith'
}
})
.source('./src')
.destination('./public')
.clean(true)
.use(markdown())
.use(layouts({
engine: 'handlebars',
directory: './layouts',
default: 'article.html',
pattern: ["*/*/*html", "*/*html", "*html"]
}))
.build(function(err) {
if (err) {
console.log(err);
} else {
console.log('Site built!');
}
});
package.json
{
"name": "electroniq",
"version": "1.0.0",
"private": true,
"description": "Test blog with Metalsmith",
"author": "GV",
"dependencies": {
"handlebars": "^4.0.11",
"jstransformer-handlebars": "^1.1.0",
"metalsmith": "^2.3.0",
"metalsmith-collections": "^0.9.0",
"metalsmith-jstransformer": "^0.13.2",
"metalsmith-layouts": "^2.1.0",
"metalsmith-markdown": "^0.2.2",
"metalsmith-permalinks": "^0.5.0"
},
"main": "build.js",
"scripts": {
"prestart": "npm install",
"start": "node ."
}
}
Folder structure
-layouts
- -article.html
-node_modules
-public
-src
- -hello-universe.md
-build.js
-package.json
Rename article.html
to article.hbs
and change the default layout accordingly.