var through = require('through2');
var moment = require("moment")
var Post = require("./../blog/post")
var postItems = require("./../blog/post_items")
var marked= require('marked');

function getTitle(filename){
    return filename.split("/")[2].replace(/\.jade$/ , "");
}

function getDate(filename) {
    return moment(filename.split("/")[1]).toDate();
}

function getId(filename) {
    return filename;
}
function MarkDownFilter() {
    var stream = through.obj(function(file, enc, cb) {
        // console.log(marked(file.contents.toString("utf-8")))
        if(file.relative.match(/\.md$/)){
            var content = marked(file.contents.toString("utf-8"));
            var post = new Post(
                "TODOID",
                "TODO title",
                content , 
                "2015-02-16"
            )
            postItems.add(post)
            this.push(post.toFile());
        }
        cb();
    });
    return stream;
};

module.exports = MarkDownFilter;



@@ -174,16 +174,50 @@
 arked');
+%0Avar utils = require(%22./../utils%22)
 %0A%0Afuncti
@@ -288,13 +288,10 @@
 (/%5C.
-jade$
+md
 / , 
@@ -420,24 +420,34 @@
  return 
+utils.md5(
 filename
 ;%0A%7D%0Afunc
@@ -438,16 +438,17 @@
 filename
+)
 ;%0A%7D%0Afunc
@@ -752,46 +752,69 @@
     
-%22TODOID%22,%0A                %22TODO title%22
+getId(file.relative),%0A                getTitle(file.relative)
 ,%0A  
@@ -858,20 +858,30 @@
     
-%222015-02-16%22
+getDate(file.relative)
 %0A   

support markdown