将渲染器和目的地分开的gulp降价

时间:2015-10-04 08:23:50

标签: gulp

我试图获取输入降价文件,通过2个不同的渲染器运行它,并将输出保存到不同的文件夹。我的计划是使用blockquotes来保持特定内容不会在其中一个输出中呈现。这是我的gulp文件:

var gulp     = require('gulp'),
    marked   = require('marked'),
    markdown = require('gulp-markdown'),
    cache    = require('gulp-cached'),
    lazypipe = require('lazypipe'),
    merge    = require('merge-stream');

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

    // setup mlive
    var mlive_renderer = new marked.Renderer();
    mlive_renderer.blockquote = function (quote) {
        return quote;
    };

    var mliveTasks = lazypipe()
        .pipe(markdown, {
            renderer: mlive_renderer
        });


    // setup hudsonvilleathletics
    var hudsonvilleathleics_renderer = new marked.Renderer();
    hudsonvilleathleics_renderer.blockquote = function(){ return ''; };

    var hudsonvilleathleticsTasks = lazypipe()
        .pipe(markdown, {
            renderer: hudsonvilleathleics_renderer
        });



    // create out pipe of src content
    var sources = gulp.src('src/**/*.md')
        .pipe(cache('markdown'));


    var mlive = sources
        .pipe(mliveTasks())
        .pipe(gulp.dest('mlive'));


    var hudsonvilleathletics = sources
        .pipe(hudsonvilleathleticsTasks())
        .pipe(gulp.dest('hudsonvilleathletics'));



    return merge(mlive, hudsonvilleathletics);

});

运行此操作完成没有错误,但两个内容都相同,并且标题周围有其他p标记。如果我注释掉一个并且只返回另一个它就可以了。

我做错了什么?

输入文件:

## This is a heading

> This is mlive only stuff

Here's some other stuff for both.

> one more for mlive

和输出(两者相同)

<p><h2 id="this-is-a-heading">This is a heading</h2></p>
<p>This is mlive only stuff</p>
<p>Here&#39;s some other stuff for both.</p>
<p>one more for mlive</p>

1 个答案:

答案 0 :(得分:0)

经过多次挖掘后,我偶然发现gulp-mirror,并设法让这个工作。使用它我能够将目标调用移动到lazypipes,然后将源镜像到它们。这是新的gulpfile(附加调整以从标题中删除ID)

var gulp     = require('gulp'),
    marked   = require('marked'),
    markdown = require('gulp-markdown'),
    cache    = require('gulp-cached'),
    lazypipe = require('lazypipe'),
    mirror   = require('gulp-mirror');

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

    // start of by removing the id's for headings
    var heading = function (text, level) {
        return '<h' + level + '>' + text + '</h' + level + '>\n';
    };

    /*
     *  mLive Setup
     *
     *  convert any block quotes back to regular old p tags and save in the mlive folder
    */
    var mliveRenderer = new marked.Renderer();
    mliveRenderer.heading = heading;
    mliveRenderer.blockquote = function(quote){
        return quote;
    };

    var mliveTasks = lazypipe()
        .pipe(markdown, {
            renderer: mliveRenderer
        })
        .pipe(gulp.dest, 'mlive/');


    /*
    *   HudsonvilleAthletics Setup
    *
    *   completely remove anything in block quotes and save to the other folder
    */
    var hudsonvilleathleticsRenderer = new marked.Renderer();
    hudsonvilleathleticsRenderer.heading = heading;
    hudsonvilleathleticsRenderer.blockquote = function(){
        return '';
    };

    var hudsonvilleathleticsTasks = lazypipe()
        .pipe(markdown, {
            renderer: hudsonvilleathleticsRenderer
        })
        .pipe(gulp.dest, 'hudsonvilleathletics/');


    /*
    *   Finally run everything
    */
    return sources = gulp.src('src/**/*.md')
        .pipe(cache('markdown'))
        .pipe(mirror(
            mliveTasks(),
            hudsonvilleathleticsTasks()
        ));
});