-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
69 lines (59 loc) · 1.82 KB
/
gulpfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
var gulp = require('gulp'),
minimist = require('minimist'),
swig = require('gulp-swig'),
rename = require('gulp-rename'),
taskListing = require('gulp-task-listing'),
replace = require('gulp-replace');;
var vfs = require('vinyl-fs');
gulp.task('help', taskListing);
gulp.task('default', function() {
// do stuff
});
gulp.task('build-api', function() {
return gulp.src('_posts/*')
.pipe(replace(/layout\: post/, 'layout: json\nsitemap: false'))
.pipe(vfs.dest('api/v01/posts', { overwrite: true }));
});
// Add a new post
gulp.task('new-draft', function() {
var options = minimist(process.argv.slice(2));
if (typeof options.date == 'undefined') {
var date = new Date();
var month = date.getMonth() + 1;
var day = date.getDate();
var time = {
year: date.getFullYear(),
month: (month < 10 ) ? '0' + month : month,
day: (day < 10 ) ? '0' + day : day,
toString: function() {
return this.year + '-' + this.month + '-' + this.day;
}
}
}
else {
var time = { toString: function() { return options.date; }};
}
if (typeof options.title != 'undefined') {
var title = options.title;
var fullTitle = time.toString() + '-' + title.replace(/[^a-z0-9]/gi, '-').toLowerCase() + '.md';
var swigOptions = {
data: {
title: title,
date: time.toString(),
body: options.body
}
}
return gulp.src('_templates/post.template')
.pipe(swig(swigOptions))
.pipe(rename(fullTitle))
.pipe(vfs.dest('_drafts', { overwrite: false }));
}
else {
console.log("Please enter a title");
}
});
gulp.task('publish-draft', function() {
var options = minimist(process.argv.slice(1));
return gulp.src('_drafts/' + options.draft)
.pipe(vfs.dest('_posts', {overwrite: options.overwrite | false}));
})