我试图让布局按照文档和这个示例工作,但我无法让布局工作。我在 github 帖子中看到,我还需要安装 jstransformers(我做了)和车把版本。
布局文档提供了如何使用 CLI 执行此操作的示例,但我看不出哪里出错了。我尝试了多种布局选项,包括将它们留空,但似乎没有任何效果。
构建.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!');
}
});
包.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 ."
}
}
文件夹结构
-layouts
- -article.html
-node_modules
-public
-src
- -hello-universe.md
-build.js
-package.json