-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
131 lines (119 loc) · 4.45 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/*global -$ */
'use strict';
// generated on 2015-02-28 using generator-gulp-webapp 0.3.0
var gulp = require('gulp'),
gp = require('gulp-load-plugins')(),
sitemap = require('gulp-sitemap'),
useref = require('gulp-useref'),
revall = require('gulp-rev-all'),
pleeease = require('gulp-pleeease'),
filter = require('gulp-filter'),
smoosher = require('gulp-smoosher'),
uglify = require('gulp-uglify'),
jsValidate = require('gulp-jsvalidate'),
csso = require('gulp-csso'),
rename = require('gulp-rename'),
browserSync = require('browser-sync'),
reload = browserSync.reload,
// htmlmin = require('gulp-htmlmin'),
robots = require('gulp-robots'),
permalinks = require('./lib/permalinks'),
bufferPages = require('./lib/pages'),
config = require('./config'),
pkg = require('./package'),
buildDir = pkg.config.buildDir,
deployDir = pkg.config.deployDir;
gulp.task('images', function () {
return gulp.src('assets/images/**/*')
.pipe(gp.cache(gp.imagemin({
progressive: true,
interlaced: true,
// don't remove IDs from SVGs, they are often used
// as hooks for embedding and styling
svgoPlugins: [{cleanupIDs: false}]
})))
.pipe(gulp.dest(buildDir + '/assets/images'));
});
gulp.task('buffer', function () {
gulp.src('content/pages/**/*.md')
.pipe(bufferPages('buffer', 'buffer.json', 'data', config))
.pipe(gulp.dest('data'));
});
gulp.task('rss', function () {
gulp.src('content/pages/**/*.md')
.pipe(bufferPages('rss', 'rss.xml', buildDir, config))
.pipe(gulp.dest(buildDir));
});
gulp.task('styles', function () {
return gulp.src('assets/styles/main.scss', {layout: null})
.pipe(gp.sourcemaps.init())
.pipe(gp.sass({
outputStyle: 'nested', // libsass doesn't support expanded yet
precision: 10,
includePaths: ['.', './bower_components'],
// [todo] - Error out when there's Sass errors instead
onError: console.error.bind(console, 'Sass error:')
})
)
.pipe(pleeease({browsers: ['last 1 version']}))
.pipe(gp.sourcemaps.write())
.pipe(gulp.dest('.tmp/assets/styles'))
.pipe(reload({stream: true}));
});
gulp.task('fonts', function () {
return gulp.src(require('main-bower-files')({
filter: '**/*.{eot,svg,ttf,woff,woff2}'
}).concat('assets/fonts/**/*'))
.pipe(gulp.dest(buildDir + '/assets/fonts'));
});
gulp.task('html', ['fonts', 'styles', 'images'], function () {
var userefAssets = useref.assets({searchPath: ['.tmp', 'assets', '.']}),
jsFilter = filter('**/*.js'),
cssFilter = filter('**/*.css');
return gulp.src('.tmp/**/*.html')
.pipe(robots({ out: buildDir + '/robots.txt' }))
.pipe(userefAssets) // Concatenate with gulp-useref
.pipe(jsFilter)
.pipe(jsValidate())
.pipe(uglify()) // Minify any javascript sources
.pipe(jsFilter.restore())
.pipe(cssFilter)
.pipe(csso()) // Minify any CSS sources
.pipe(cssFilter.restore())
.pipe(userefAssets.restore())
.pipe(useref())
// .pipe(htmlmin({
// removeComments: true,
// collapseWhiteSpace: true,
// collapseBooleanAttributes: true,
// removeRedundantAttributes: true,
// removeScriptTypeAttributes: true,
// removeStyleLinkTypeAttributes: true,
// maxLineLength: 80
// }))
.pipe(rename(function (path) {
if (path.extname === '.html' && path.basename !== 'index') {
path.basename = 'index';
}
}))
.pipe(smoosher({
base: '.'
}))
.pipe(gulp.dest(buildDir));
});
gulp.task('sitemap',function () {
return gulp.src('content/pages/**/*.md')
.pipe(permalinks(true))
.pipe(sitemap({
siteUrl: pkg.homepage
})) // Returns sitemap.xml
.pipe(gulp.dest(buildDir));
});
gulp.task('cache-busting', function () {
gulp.src(buildDir + '/**')
.pipe(revall({ ignore: [/^\/favicon.ico$/g, '.html', '.xml', '.txt'] }))
.pipe(gulp.dest(deployDir));
});
gulp.task('build', ['html', 'sitemap', 'rss'], function () {
return gulp.src(buildDir + '/**/*').pipe(gp.size({title: 'build', gzip: true}));
});