This repository has been archived by the owner on Jan 26, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
70 lines (65 loc) · 2.12 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
var DOCROOT = 'build',
SRCROOT = 'src',
TEMPLATEROOT = 'templates',
PARTIALSROOT = TEMPLATEROOT + '/partials',
_ = require('lodash'),
fs = require('fs'),
gulp = require('gulp'),
connect = require('gulp-connect'),
gulpsmith = require('gulpsmith'),
gulp_front_matter = require('gulp-front-matter'),
Handlebars = require('handlebars'),
fingerprint = require('metalsmith-fingerprint'),
markdown = require('metalsmith-markdown'),
templates = require('metalsmith-templates'),
sass = require('metalsmith-sass');
// Function to remove original compiled css files from being copied into destination
// folder since fingerprinting will place its own copy in.
var removeFingerprintOriginals = function() {
return function (files, metalsmith, done) {
var metadata = metalsmith.metadata();
if (_.has(metadata, 'fingerprint')) {
_.forIn(metadata.fingerprint, function(value, key) {
if (_.has(files, key)) {
delete files[key];
}
});
}
done();
}
};
gulp.task('build', function() {
// Register partials, based on filename.
// E.G.: `header.handlebars` becomes the `header` partial.
_.each(fs.readdirSync(PARTIALSROOT), function(file){
var name = file.split(".")[0],
contents = fs.readFileSync(__dirname + '/' + PARTIALSROOT + '/' + file).toString();
Handlebars.unregisterPartial(name);
Handlebars.registerPartial(name, contents);
});
gulp.src(SRCROOT + "/**/*")
.pipe(gulp_front_matter())
.on("data", function(file) {
_.assign(file, file.frontMatter);
delete file.frontMatter;
})
.pipe(
gulpsmith()
.use(markdown())
.use(sass({outputStyle: 'compressed'}))
.use(fingerprint({pattern: ['styles/*.css', 'js/*.js']}))
.use(removeFingerprintOriginals())
.use(templates({
engine: 'handlebars'
}))
).pipe(connect.reload())
.pipe(gulp.dest("./build"));
});
gulp.task('serve', function() {
connect.server({
root: DOCROOT,
livereload: true
});
gulp.watch([SRCROOT + '/**/*', TEMPLATEROOT + '/**/*'], ['build']);
});
gulp.task('default', ['build']);