试图按照docs和this example使布局正常工作,但我无法使布局正常工作。我在github帖子中看到了这一点,我还需要安装jstransformers(我做了)和handlebars版本。 layout docs给出了如何通过CLI进行操作的示例,但我看不到哪里出了问题。我已经尝试过各种布局选项,包括将它们留空,但似乎没有任何效果。任何指针将不胜感激。
Build.js
var Jasmine = require('jasmine');
var HtmlReporter = require('jasmine-pretty-html-reporter').Reporter;
var jasmine = new Jasmine();
jasmine.loadConfigFile('./spec/support/jasmine.json');
// options object
jasmine.addReporter(new HtmlReporter({
path: path.join(__dirname,'results')
}));
jasmine.execute();
package.json
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!');
}
});
文件夹结构
{
"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 ."
}
}
答案 0 :(得分:-1)
将article.html
重命名为article.hbs
,并相应地更改默认布局。