gpt4 book ai didi

node.js - gulp-front-matter 把我的前文放在哪里?

转载 作者:太空宇宙 更新时间:2023-11-04 00:41:29 25 4
gpt4 key购买 nike

我正在尝试使用这个npm module两者都剥离一些front matter从 Markdown 文件中获取,然后让我访问它删除的 Markdown。这让我想到了我的问题(模块页面的代码):

var frontMatter = require('gulp-front-matter');

gulp.task('blog-posts', function() {
gulp.src('./posts/*.md')
.pipe(frontMatter({ // optional configuration
property: 'frontMatter', // property added to file object
remove: true // should we remove front-matter header?
}))
.pipe(…);
});

所以有注释//property added to the file object。这意味着什么?我怎样才能获得前题数据?也许更准确,我如何访问"file"对象?

最佳答案

没关系。该模块假设人们将使用 this module它允许访问file对象。我似乎找到了我的问题的答案:gulp-data 希望成为“将数据附加到文件对象以供其他插件使用”的标准方式,这显然是 gulp 目前还没有标准的方式。

工作代码:

var gulp = require('gulp');
var markdown = require('gulp-markdown');
var frontMatter = require('gulp-front-matter');
var data = require('gulp-data');

markdown.marked.setOptions({
gfm: false
});

gulp.task('default', function () {
return gulp.src('*.md')
.pipe(frontMatter({
property: 'pig',
remove: true
}))
.pipe(data(function(file) {
console.log(file.pig.layout);
}))
.pipe(markdown({tables: true}))
.pipe(gulp.dest('dist'));

});

关于node.js - gulp-front-matter 把我的前文放在哪里?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36560482/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com