-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
131 lines (110 loc) · 3.1 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
var del = require('del');
var _ = require('lodash');
var gulp = require('gulp');
var debug = require('gulp-debug');
var frontMatter = require('gulp-front-matter');
var imagemin = require('gulp-imagemin');
var less = require('gulp-less');
var livereload = require('gulp-livereload');
var gulpsmith = require('gulpsmith');
var jpegtran = require('imagemin-jpegtran');
var marked = require('marked');
var collections = require('metalsmith-collections');
var markdown = require('metalsmith-markdown');
var metadata = require('metalsmith-metadata');
var permalinks = require('metalsmith-permalinks');
var templates = require('metalsmith-templates');
var path = require('path');
//var process = require('process');
var updateProjectsFromGithub = require('./gulp/updateProjectsFromGithub');
//TODO: add pagination ?, gulp-sourcemaps
//TODO: add to jade moment or somethings
gulp.task('clean:dist', function (done) {
del(['dist/*'], done);
});
gulp.task('build:html', function () {
return gulp.src(['./pages/**/*.md', './config.yaml'])
.pipe(frontMatter().on('data', function (file) {
_.assign(file, file.frontMatter);
delete file.frontMatter;
}))
.pipe(gulpsmith()
.use(metadata({
config: 'config.yaml'
}))
.use(collections({
projects: {
pattern: 'projects/*.md'
}
}))
.use(updateProjectsFromGithub({
clientId: process.env.UPDATE_PROJECTS_FROM_GITHUB_CLIENT_ID,
secret: process.env.UPDATE_PROJECTS_FROM_GITHUB_SECRET,
sortBy: 'stars',
reverse: true
}))
.use(markdown())
.use(permalinks())
.use(templates({
engine: 'jade',
stringify: function(obj) {
var cache = [];
var str = JSON.stringify(obj, function(key, value) {
if (typeof value === 'object' && value !== null) {
if (cache.indexOf(value) !== -1) {
// Circular reference found, discard key
return;
}
// Store value in our collection
cache.push(value);
}
return value;
});
cache = null; // Enable garbage collection
return str;
}
}))
)
.pipe(debug({title: 'build:html'}))
.pipe(livereload())
.pipe(gulp.dest('./dist'));
});
gulp.task('build:images:assets', function() {
return gulp.src('assets/**/*.jpg')
.pipe(imagemin({
progressive: true,
use: [jpegtran()]
}))
.pipe(gulp.dest('dist/images'));
});
gulp.task('build:images:projects', function() {
return gulp.src('pages/**/*.jpg')
.pipe(imagemin({
progressive: true,
use: [jpegtran()]
}))
.pipe(gulp.dest('dist/images'));
});
gulp.task('build:images', gulp.parallel('build:images:assets', 'build:images:projects'));
gulp.task('build:styles', function() {
return gulp.src('./templates/styles/**/*.less')
.pipe(less({
paths: [ path.join(__dirname, 'node_modules', 'bootswatch') ]
}))
.pipe(gulp.dest('dist/css'));
});
gulp.task('build', gulp.parallel(
'build:html',
'build:images',
'build:styles'));
gulp.task('watch', function () {
livereload.listen();
gulp.watch([
'config.yaml',
'assets/**/*',
'pages/**/*',
'templates/**/*'
],
gulp.series('build'));
});
gulp.task('default', gulp.series('clean:dist', 'build'));