-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathgulpfile.babel.js
101 lines (91 loc) · 2.24 KB
/
gulpfile.babel.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
/* @flow */
import path from 'path';
import glob from 'glob';
import googleWebFonts from 'gulp-google-webfonts';
import gulp from 'gulp';
import imagemin from 'gulp-imagemin';
import inlinesource from 'gulp-inline-source';
import minifyInline from 'gulp-minify-inline';
import Pageres from 'pageres';
import uncss from 'gulp-uncss';
gulp.task('uncss', () =>
gulp
.src('./public/styles.css')
.pipe(
uncss({
html: ['public/**/*.html'],
ignore: [
'.b--dark-gray',
'.b--red',
'.b--white',
'.bg-dark-gray',
'.bg-white',
'.dark-gray',
'.gray',
'.red',
'.white-60',
'.white',
/^\.dark-mode .+/,
/^\.light-mode .+/,
/^\.wf-active .+/,
],
})
)
.pipe(gulp.dest('./public'))
);
gulp.task('inlinesource', ['uncss'], () =>
gulp
.src('./public/**/*.html')
.pipe(inlinesource({attribute: 'data-inline'}))
.pipe(gulp.dest('./public'))
);
gulp.task('minifyinline', ['inlinesource'], () =>
gulp
.src('./public/**/*.html')
.pipe(minifyInline())
.pipe(gulp.dest('./public'))
);
gulp.task('fonts', () =>
gulp
.src('./fonts.list')
.pipe(
googleWebFonts({
fontsDir: 'fonts/',
cssDir: './',
cssFilename: 'fonts.css',
})
)
.pipe(gulp.dest('./public'))
);
gulp.task('pageres', ['minifyinline', 'fonts'], () => {
glob.sync('public/blog/*/index.html').forEach((file: string) => {
const pageres = new Pageres({
crop: true,
filename: 'post-screenshot',
delay: 2,
scale: 2,
css: `
.headroom-wrapper { display: none }
#content { max-width: 48rem }
`,
format: 'jpg',
});
pageres
.src(file, ['1200x630'])
.dest(path.dirname(file))
.run((err: ?Error) => {
if (err) {
console.log(err); // eslint-disable-line no-console
}
});
});
});
// we don't actually need to use this
// since images are already compressed with imageoptim
gulp.task('imagemin', () =>
gulp
.src('./public/**/*.{jpg,jpeg,png,svg}')
.pipe(imagemin())
.pipe(gulp.dest('./public'))
);
gulp.task('default', ['minifyinline', 'fonts', 'pageres']);