通过吞食前锋的价值来吞噬包裹 [英] Passing gulp-front-matter value to gulp-wrap
问题描述
我希望能做这样的事情:
gulp.src('src / *。html')
.pipe(fm({
property:'fm'
)))
.pipe(wrap({
src:fm ['template']
)))
其中模板
是一个在前端的价值。我可以创建一个单独的函数,我使用gulp-tap来传递值,但我希望保持
简单。我不认为 gulp-wrap
支持访问前端变量。
你需要传递一个函数作为第一个参数 gulp-wrap $ c $
$ b gulp-wrap
的文件说明
当一个函数被调用时,函数将返回
模板内容。这个函数将数据对象作为第一个
参数。
类似以下内容应该可以工作。
$ b $
var gulp = require('gulp')
var fm = require('gulp-front-matter')
var wrap = require('gulp-wrap')
var fs = require('fs')
gulp.src('src / *。html')
(函数(数据){
返回fs.readFileSync('path / to / layout_dir /'+ data.file。 ('build /'))
另请参阅:
吞噬前方物品+通过Nunjucks降价
I'm hoping to do something like this:
gulp.src('src/*.html')
.pipe(fm ({
property: 'fm'
}))
.pipe(wrap({
src: fm['template']
}))
where template
is a value in the front-matter. I can create a separate function where I pass the value using gulp-tap but I was hoping to keep it
"simple". I don't think gulp-wrap
supports accessing front-matter vars.
You need to pass a function as the first argument of gulp-wrap
.
The document of gulp-wrap
says
When a Function then the function will be called and should return the template content. This function get the data object as first parameter.
Something like the following should work.
var gulp = require('gulp')
var fm = require('gulp-front-matter')
var wrap = require('gulp-wrap')
var fs = require('fs')
gulp.src('src/*.html')
.pipe(fm({property: 'fm'}))
.pipe(wrap(function (data) {
return fs.readFileSync('path/to/layout_dir/' + data.file.fm.template + '.tpl').toString()
}))
.pipe(gulp.dest('build/'))
See also: Gulp Front Matter +Markdown through Nunjucks
这篇关于通过吞食前锋的价值来吞噬包裹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!