我正在尝试使用现场金属匠在我的源dir的子目录中对文件做一些就地模板处理。它不起作用。模板标记不会被正面的内容所取代。
我的构建脚本:
var Metalsmith = require('metalsmith'),
inplace = require('metalsmith-in-place'),
nunjucks = require('nunjucks');
Metalsmith(__dirname)
.source('./source')
.use(inplace({
engine: 'nunjucks',
pattern: '*.html',
directory: 'source/deeper'
}))
.destination('./build')
.build(function(err) {
if (err) {
console.log(err);
}
else {
console.info('Built it.');
}
});我的模板:
metalsmith_debug$ cat source/deeper/index.html
---
title: My pets
---
{{title}}我的产出:
metalsmith_debug$ cat build/deeper/index.html
{{title}}它适用于source中的文件;但我需要它在子目录上工作。
发布于 2016-04-08 11:16:24
几项更改:build.js
var Metalsmith = require('metalsmith');
var inplace = require('metalsmith-in-place');
// var nunjucks = require('nunjucks');
Metalsmith(__dirname)
.source('./source')
.use(inplace({
engine: 'nunjucks',
pattern: '**/*.html' // modified pattern
// directory: 'source/deeper' // Not needed
}))
.destination('./build')
.build(function(err) {
if (err) {
console.log(err);
}
else {
console.info('Built it.');
}
});metalsmith-in-place使用consolidate,这需要在必要时使用。(行可移除)inplace中的inplace修改为**/*.html。有关更多信息,请参见球状图案。directory在inplace中是不需要的。(行可移除)..。以及对source/deeper/index.html的一个小改动
---
title: My pets
---
{{ title }}{{ title }} - 恩朱克斯周围添加空间似乎认为这很重要。现在应该为你工作,如果没有,请告诉我。
发布于 2017-11-18 12:40:52
接受的答案现在已经过时了,因为metalsmith-in-place转而使用jstransformer框架而不是consolidate。
我写了一篇关于如何使用in-place插件将Nunjucks与Metalsmith配对的文章:
下面是一个缩小了的工作示例:
const Metalsmith = require('metalsmith');
const inPlace = require('metalsmith-in-place');
Metalsmith(__dirname)
.source('./src')
.destination('./build')
.use(inPlace({
pattern: '**/*.njk',
engineOptions: {
path: __dirname + '/src'
}
}))
.build(function (error) {
if (error) {
throw error;
}
})
;发布于 2016-04-08 00:20:00
您在inplace配置中的inplace很可能应该是**/*.html,而不仅仅是*.html
https://stackoverflow.com/questions/36488739
复制相似问题