【发布时间】:2014-05-20 15:04:23
【问题描述】:
我想将 gulp frontmatters 输出传递给我在 Gulp(gulp 模板)中使用的另一个函数。我认为我的语法是正确的,但一定是做错了什么,因为它不起作用。
我使用的 gulp 插件是:Gulp frontmatter 和 Gulp template。我正在尝试将一个名为page 的对象从frontmatter() 传递给template(),如下所示:
.pipe(frontMatter({
property: 'page' // the name of the property added to the file object
}))
.pipe(template(page)) // passing the page object to the template plugin here
这行不通。我做错了什么?
供参考:这是我的 gulpfile.js 中的完整代码
// Gulp modules
var gulp = require( 'gulp' );
var markdown = require( 'gulp-markdown' );
var frontMatter = require( 'gulp-front-matter' );
var template = require( 'gulp-template' );
gulp.task('default', function () {
return gulp.src( ['./**/*.{md,markdown}'] )
.pipe(frontMatter({
property: 'page' // property added to file object
}))
.pipe(template(page))
.pipe(markdown())
.pipe(gulp.dest(grOutput));
});
这是我正在使用的模板(test/test.md):
---
name: MyName
---
Text
<%= page.name %>
Text
这是我收到的错误消息:
[gulp] Using gulpfile D:\Dropbox\Github\graphene\gulpfile.js
[gulp] Starting 'default'...
[gulp] 'default' errored after 7.49 ms page is not defined
D:\Dropbox\Github\graphene\node_modules\gulp-front-matter\node_modules\event-stream\node_modules\map-stream\index.js:103
throw err
^
expected '<document start>', but found <block mapping end>
in "undefined", line 12, column 1
at ParserError.YAMLError (D:\Dropbox\Github\graphene\node_modules\gulp-front-matter\node_modules\front-matter\node_modules\yaml-js\lib\errors.js:72:46)
at ParserError.MarkedYAMLError (D:\Dropbox\Github\graphene\node_modules\gulp-front-matter\node_modules\front-matter\node_modules\yaml-js\lib\errors.js:88:45)
at new ParserError (D:\Dropbox\Github\graphene\node_modules\gulp-front-matter\node_modules\front-matter\node_modules\yaml-js\lib\parser.js:17:48)
at Constructor.Parser.Parser.parse_document_start (D:\Dropbox\Github\graphene\node_modules\gulp-front-matter\node_modules\front-matter\node_modules\yaml-js\lib\parser.js:158:17)
at Constructor.Parser.Parser.check_event (D:\Dropbox\Github\graphene\node_modules\gulp-front-matter\node_modules\front-matter\node_modules\yaml-js\lib\parser.js:63:48)
at Constructor.Composer.Composer.get_single_node (D:\Dropbox\Github\graphene\node_modules\gulp-front-matter\node_modules\front-matter\node_modules\yaml-js\lib\composer.js:55:17)
at Constructor.BaseConstructor.BaseConstructor.get_single_data (D:\Dropbox\Github\graphene\node_modules\gulp-front-matter\node_modules\front-matter\node_modules\yaml-js\lib\constructor.js:78:19)
at load (D:\Dropbox\Github\graphene\node_modules\gulp-front-matter\node_modules\front-matter\node_modules\yaml-js\lib\yaml.js:113:19)
at parse (D:\Dropbox\Github\graphene\node_modules\gulp-front-matter\node_modules\front-matter\index.js:26:27)
at extractor (D:\Dropbox\Github\graphene\node_modules\gulp-front-matter\node_modules\front-matter\index.js:19:34)
【问题讨论】:
标签: javascript node.js gulp lodash