-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gulpfile.js
110 lines (100 loc) · 3.25 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// gulp related
var gulp = require('gulp'),
gulp_front_matter = require('gulp-front-matter'),
assign = require('lodash').assign,
clean = require('gulp-clean'),
connect = require('gulp-connect'),
less = require('gulp-less'),
autoprefixer = require('gulp-autoprefixer'),
runSequence = require('run-sequence'),
s3 = require('gulp-s3-upload'),
path = require('path');
// Metalsmith related
var gulpsmith = require('gulpsmith'),
markdown = require('metalsmith-markdown'),
templates = require('metalsmith-templates'),
permalinks = require('metalsmith-permalinks'),
collections = require('metalsmith-collections'),
Handlebars = require('handlebars'),
fs = require('fs');
// Handlebars
Handlebars.registerPartial('header', fs.readFileSync(__dirname + '/templates/partials/header.hbt').toString());
Handlebars.registerPartial('footer', fs.readFileSync(__dirname + '/templates/partials/footer.hbt').toString());
Handlebars.registerHelper("log", function(something) {
console.log(something);
});
// Gulp tasks
gulp.task('default', function (cb) {
runSequence('clean', ['metalsmith', 'less'], cb);
});
gulp.task('deploy', ['default'], function () {
var s3Deploy = s3(require('./.s3.json'));
setTimeout(function(){
gulp.src("./build/**/*")
.pipe(s3Deploy({
Bucket: 'mikevalstar.com',
ACL: 'public-read'
}));
}, 1000); // timeout to let metalsmith complete
});
gulp.task('watch', ['connect'], function() {
gulp.watch(['./src/**/*', './templates/**/*'], ['metalsmith']);
gulp.watch('./less/**/*', ['less']);
});
gulp.task('connect', function() {
connect.server({
root: './build',
livereload: true
});
});
gulp.task('metalsmith', function() {
gulp.src("./src/**/*")
.pipe(gulp_front_matter()).on("data", function(file) {
assign(file, file.frontMatter);
delete file.frontMatter;
}).pipe(
gulpsmith()
.use(collections({
page: {
pattern: 'pages/*.md'
},
post: {
pattern: 'posts/*.md',
sortBy: 'datetime',
reverse: true
}
}))
.use(markdown())
.use(templates('handlebars'))
.use(permalinks(':collection/:link'))
).pipe(gulp.dest("./build"))
.pipe(connect.reload());
});
gulp.task('less', function () {
return gulp.src('./less/*.less')
.pipe(less({
paths: [path.join(__dirname, 'less', 'includes')]
}))
.pipe(autoprefixer(
{
browsers: [
'> 1%',
'last 4 versions',
'firefox >= 4',
'safari 7',
'safari 8',
'IE 8',
'IE 9',
'IE 10',
'IE 11'
],
cascade: false
}
))
.pipe(gulp.dest('./build/css'))
.pipe(connect.reload());
});
gulp.task('clean', function() {
return gulp.src('./build', {read: false})
.pipe(clean());
});