-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.babel.js
124 lines (105 loc) · 2.96 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
'use strict';
import gulp from 'gulp';
import gulpLoadPlugins from 'gulp-load-plugins';
import marked from 'marked';
import Prism from 'node-prismjs';
import pug from 'pug';
import del from 'del';
import browserSync from 'browser-sync';
marked.setOptions({
highlight: function(code, lang, cb) {
const highlighted = (Prism.languages[lang])
? Prism.highlight(code, Prism.languages[lang])
: code;
return highlighted;
}
});
pug.filters.code = function(str, options, locals) {
const opts = Object.assign({}, options || {}, locals || {});
const lang = opts.lang || 'plain';
const start = (typeof opts.start === 'number')? opts.start : null;
const highlighted = (Prism.languages[opts.lang])
? Prism.highlight(str, Prism.languages[opts.lang])
: str;
const lineNumberGutter = (start !== null)
? `<span class="line-numbers-rows" style="counter-reset: linenumber ${start - 1}">`
+ Array(str.split('\n').length).join('<span></span>')
+ `</span>`
: '';
return `<pre class="${(start !== null)? 'line-numbers' : ''}" ${(start !== null)? 'data-start="'+start+'"' : ''}>`
+ `<code class="language-${lang}">${lineNumberGutter}${highlighted}</code>`
+ `</pre>`;
}
pug.filters.marked = (str, options) => {
return marked(str, options);
}
const $ = gulpLoadPlugins();
const plumberOpt = {
errorHandler: function(err) {
console.error(err.stack);
this.emit('end');
},
}
gulp.task('default', ['pug', 'assets', 'stylus']);
gulp.task('pug', () => {
gulp.src('content/hyoshi.pug')
.pipe($.plumber(plumberOpt))
.pipe($.pug({
pug: pug,
pretty: true,
}))
.pipe(gulp.dest('dest/'));
gulp.src('content/index.pug')
.pipe($.plumber(plumberOpt))
.pipe($.pug({
pug: pug,
pretty: true,
}))
.pipe(gulp.dest('dest/'));
});
gulp.task('assets', ['assets:delete'], () =>
gulp.src('content/assets/**/*')
.pipe(gulp.dest('dest/assets/'))
);
gulp.task('assets:delete',
del.bind(null, ['dest/assets/**/*'])
);
gulp.task('stylus', () => {
gulp.src('style/hyoshi.styl')
.pipe($.plumber(plumberOpt))
.pipe($.stylus({
'include css': true,
}))
.pipe(gulp.dest('dest/'));
gulp.src('style/main.styl')
.pipe($.plumber(plumberOpt))
.pipe($.sourcemaps.init())
.pipe($.stylus({
'include css': true,
}))
.pipe($.sourcemaps.write('.'))
.pipe(gulp.dest('dest/'))
.pipe(browserSync.reload({
stream: true,
}));
});
gulp.task('browsersync', () => {
browserSync({
server: {
baseDir: 'dest/',
index: 'index.html',
},
});
});
gulp.task('bs-reload', () => {
browserSync.reload();
})
gulp.task('watch', ['default', 'browsersync'], () => {
gulp.watch('content/**/*.pug', ['pug']);
gulp.watch('content/assets/**/*', ['assets']);
gulp.watch('style/**/*.styl', ['stylus']);
gulp.watch('dest/*.html', ['bs-reload']);
});
gulp.task('watch:stylus', ['stylus'], () => {
gulp.watch('style/**/*.styl', ['stylus']);
});