-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
100 lines (89 loc) · 3.05 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
var gulp = require('gulp')
var frontmatter = require('gulp-front-matter')
var markdown = require('gulp-markdown')
var concat = require('gulp-concat')
var es = require('event-stream')
var fs = require('fs')
var mustache = require('mustache')
var _ = require('lodash')
var header = String(fs.readFileSync('templates/header.html'))
var footer = String(fs.readFileSync('templates/footer.html'))
var collectChildrenToPublish = function (collection) {
return es.map(function (file, cb) {
var path = file.path.split('/')
var link = path[path.length-1]
if (!file.meta.draft) {
collection.push({
title : file.meta.title,
preview : file.contents,
link : link
})
}
cb(null, file);
})
}
var template = function (template, data) {
return es.map(function(file, cb) {
var _template = String(fs.readFileSync(template));
var _data = _.mapValues(data, function (value) {
if (typeof value == 'object') return value
if (typeof value == 'string' && value.indexOf('file.') == 0) {
if (value == 'file.contents') return String(file.contents)
return file[value.split('file.')[1]]
}
})
var html = mustache.render(_template, _data, {
header : header,
footer : footer
});
file.contents = new Buffer(html);
cb(null, file);
})
}
// BLOG
gulp.task('build-blog-index',function () {
var bloglist = []
return gulp.src('src/blog/*.md')
.pipe(frontmatter({
property: 'meta'
}))
.pipe(markdown())
.pipe(collectChildrenToPublish(bloglist))
.pipe(concat('index.html'))
.pipe(template('templates/blog_index.html', { blogs : bloglist }))
.pipe(gulp.dest('blog'))
})
gulp.task('build-blog', function () {
return gulp.src('src/blog/*.md')
.pipe(frontmatter({
property: 'meta'
}))
.pipe(markdown())
.pipe(template('templates/blog.html', { page : 'file.meta', content : 'file.contents' }))
.pipe(gulp.dest('blog'));
});
// EVENTS
gulp.task('build-events-index',function () {
var bloglist = []
return gulp.src('src/events/*.md')
.pipe(frontmatter({
property: 'meta'
}))
.pipe(markdown())
.pipe(collectChildrenToPublish(bloglist))
.pipe(concat('index.html'))
.pipe(template('templates/event_index.html', { blogs : bloglist }))
.pipe(gulp.dest('events'))
})
gulp.task('build-events', function () {
return gulp.src('src/events/*.md')
.pipe(frontmatter({
property: 'meta'
}))
.pipe(markdown())
.pipe(template('templates/event.html', { page : 'file.meta', content : 'file.contents' }))
.pipe(gulp.dest('events'));
});
gulp.task('build', ['build-blog','build-blog-index','build-events', 'build-events-index'])
gulp.task('default', ['build'])
module.exports = gulp