-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
72 lines (61 loc) · 1.83 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
var gulp = require('gulp');
var yaml = require('json2yaml');
var http = require('http');
var fs = require('fs');
var gravatar = require('gravatar');
var uglify = require('gulp-uglify');
var rename = require('gulp-rename');
var shell = require('gulp-shell');
var browserSync = require('browser-sync').create();
// Get comments form Poole
gulp.task("comments", function() {
var options = {
hostname: 'pooleapp.com',
port: 80,
path: '/data/293bba1a-0eb1-4908-ac5d-1c8b5f33f311.json',
method: 'GET'
};
http.get(options, function(res) {
var body = '';
res.on('data', function(chunk) {
body += chunk;
});
res.on('end', function() {
var comments = JSON.parse(body);
// add gravatar image links if available
for (var i = 0; i < comments.sessions.length; i++) {
comments.sessions[i].avatar = gravatar.url(comments.sessions[i].email, {s: '50', r: 'pg', d: '404'});
}
// convert the json to yaml and save it for jekyll to use.
var ymlText = yaml.stringify(comments);
fs.writeFile('./src/_data/comments.yml', ymlText, function(err) {
if(err) {
console.log(err);
} else {
console.log("Comments data saved.");
}
});
});
}).on('error', function(e) {
console.log("Got error: ", e);
});
});
gulp.task('compress', function(){
return gulp.src('src/js/main.js')
.pipe(uglify())
.pipe(rename({
suffix: ".min"
}))
.pipe(gulp.dest('src/js'));
});
gulp.task('build', shell.task(['jekyll build --watch']));
gulp.task('serve', function(){
browserSync.init({
server: {
baseDir: '_site',
}
});
gulp.watch('_site/**/*.*').on('change', browserSync.reload);
gulp.watch('src/_data/*.*').on('change', browserSync.reload);
});
gulp.task('default', ['build','serve', 'compress','comments']);