-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
50 lines (43 loc) · 1.34 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
var path = require('path')
var gulp = require('gulp')
var config = require('./config.json')
var del = require('del')
var inline = require('gulp-inline-source')
var htmlmin = require('gulp-htmlmin')
var through = require('through2')
var template = require('lodash.template')
var statusCodes = require('http').STATUS_CODES
gulp.task('clean', function() {
return del(['build'])
})
gulp.task('default', ['clean'], function() {
return gulp.src('template.html')
.pipe(inline())
.pipe((function() {
return through.obj(function(file, enc, cb) {
config.compile.forEach(function(code) {
var data = {
code: code + ' ' + statusCodes[code],
title: null,
body: null,
nonce: null
}
if(config.content[code]) {
data.title = config.content[code].title
data.body = config.content[code].body
}
var clone = file.clone()
clone.path = path.resolve(clone.path, '../' + code + '.html')
clone.contents = new Buffer(template(clone.contents)(data))
this.push(clone)
}, this)
this.push(file)
return cb()
})
})())
.pipe(htmlmin({
collapseWhitespace: true,
keepClosingSlash: true
}))
.pipe(gulp.dest('build'))
})