Metalsmith 布局 - 无需处理文件
Metalsmith Layouts - No Files to Process
我试图让布局按照 docs and this example 工作,但我无法让布局工作。我在 github post 中看到我还需要安装 jstransformers(我安装了)和 handlebars 版本。
layout docs 给出了如何使用 CLI 执行此操作的示例,但我看不出哪里出错了。我尝试了各种布局选项,包括将它们留空,但似乎没有任何效果。
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 ."
}
}
文件夹结构
-layouts
- -article.html
-node_modules
-public
-src
- -hello-universe.md
-build.js
-package.json
将 article.html
重命名为 article.hbs
并相应地更改默认布局。
我试图让布局按照 docs and this example 工作,但我无法让布局工作。我在 github post 中看到我还需要安装 jstransformers(我安装了)和 handlebars 版本。
layout docs 给出了如何使用 CLI 执行此操作的示例,但我看不出哪里出错了。我尝试了各种布局选项,包括将它们留空,但似乎没有任何效果。
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 ."
}
}
文件夹结构
-layouts
- -article.html
-node_modules
-public
-src
- -hello-universe.md
-build.js
-package.json
将 article.html
重命名为 article.hbs
并相应地更改默认布局。