Created
May 11, 2015 05:43
-
-
Save hughgrigg/b44fb2313b89576d8686 to your computer and use it in GitHub Desktop.
Gulp insert front-matter date from filename
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Throwaway Gulp script to insert dates from file-names into the front-matter | |
// of content source files | |
var gulp = require('gulp'), | |
through = require('through2'); | |
gulp.task('insert-dates', function() { | |
return gulp.src('content/posts/**/*.md') | |
.pipe(through.obj( | |
function(file, enc, callback) { | |
var pathParts = file.path.split('/'), | |
pathDate = pathParts[pathParts.length - 1].substr(0, 10); | |
file.contents = new Buffer(String(file.contents).replace( | |
/match line of front matter to insert date after/, | |
'match line of front matter to insert date after\ndate: ' + pathDate | |
)); | |
return callback(null, file); | |
}) | |
) | |
.pipe(gulp.dest('content/posts')); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment