gulp 生成html文件,gulp通过markdown json生成带有jade的html文件

gulp-jade是你的用例错误的gulp插件.

>如果您要填充数据的模板流,请使用gulp-jade:

gulp.src('*.jade')

.pipe(...)

.pipe(jade({title:'Some title', text:'Some text'}))

>如果要在模板中呈现数据流,请使用gulp-wrap:

gulp.src('*.md')

.pipe(...)

.pipe(wrap({src:'path/to/my/template.jade'})

您的情况稍微困难一些,因为您需要为每个.md文件使用不同的.jade模板.幸运的是,gulp-wrap接受一个函数,该函数可以为流中的每个文件返回不同的模板:

var gulp = require('gulp');

var md = require('gulp-markdown-to-json');

var jade = require('jade');

var wrap = require('gulp-wrap');

var plumber = require('gulp-plumber');

var rename = require('gulp-rename');

var fs = require('fs');

gulp.task('docs', function() {

return gulp.src('./src/docs/pages/*.md')

.pipe(plumber()) // this just ensures that errors are logged

.pipe(md({ pedantic: true, smartypants: true }))

.pipe(wrap(function(data) {

// read correct jade template from disk

var template = 'src/docs/templates/' + data.contents.template;

return fs.readFileSync(template).toString();

}, {}, { engine: 'jade' }))

.pipe(rename({extname:'.html'}))

.pipe(gulp.dest('./dist/docs'));

});

SRC /文档/网页/ test.md

---

template: index.jade

title: Europa

---

This is a test.

SRC /文档/模板/ index.jade

doctype html

html(lang="en")

head

title=contents.title

body

h1=contents.title

div !{contents.body}

DIST /文档/的test.html

Europa

Europa

This is a test.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值