我在这里有一个名为tpage.hbs的Handlebar模板
<!DOCTYPE html>
<html lang="en">
<head>
<title>Title</title>
{{> head}}
</head>
<body>
{{> home-header}}
{{{ mdcontents }}}
</body>
</html>head和home-header是偏导数。
我有一个Markdown文件的文件夹,我想基于这个模板制作超文本标记语言页面,在模板中mdcontents所在的位置添加.md文件。
我有以下Gulpfile:
var gulp = require('gulp');
var handlebars = require('gulp-compile-handlebars');
var HB = require('Handlebars'); // I know I don't need two Handlebars imports, I'm just trying different things at this point
var uglify = require('gulp-uglify');
var markdown = require('gulp-markdown');
var tap = require('gulp-tap');
// ...
gulp.task('markhb', function() {
return gulp.src('./app/templates/tpage.hbs')
.pipe(handlebars({}, {
ignorePartials: false,
batch: ['./app/templates/partials'] /* my partials directory */
}))
.pipe(tap(function(file) {
var template = HB.compile(file.contents.toString());
console.log(file.contents.toString());
return gulp.src('./app/content/mdpages/**.md')
.pipe(markdown())
.pipe(tap(function(file) {
var data = {
mdcontents: file.contents.toString()
};
var html = template(data);
file.contents = new Buffer(html, 'utf-8'); // Buffer() is deprecated, I'll fix that later
}))
.pipe(rename({
extname: '.html'
}))
.pipe(gulp.dest('build/pages'));
}));
});所以,我的问题是,如果我保留第一个pipe调用,它会很好地加载分数,但它会忽略并完全删除mdcontents。但是,如果我删除第一个pipe调用,它会很好地呈现标记,但会去掉部分。我也不喜欢我现在使用的两个Handlebar库,但在这一点上,我只想要一个工作模板,然后再进行清理。我需要添加、删除或更改什么才能同时呈现部分参数和标记?
发布于 2018-08-22 07:27:54
使用Handlebar markdown中间件,就像这样的https://github.com/helpers/helper-markdown。
然后,我们的想法是使用带helper-markdown的Handlebar来包含该文件作为过滤器,而不是让gulp为您进行处理。
https://stackoverflow.com/questions/51955282
复制相似问题