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
132
133
134
135
136
137
138
139
140
141
142
|
var
changed = require('gulp-changed'),
gulp = require('gulp'),
hljs = require('highlight.js'),
md = require('jstransformer')(require('jstransformer-markdown-it')),
md_anchor = require('markdown-it-anchor'),
md_footnote = require('markdown-it-footnote'),
md_toc = require('markdown-it-table-of-contents'),
minifyhtml = require('gulp-minify-html'),
minifyjs = require('gulp-minify'),
notify = require('gulp-notify'),
pug = require('gulp-pug-3'),
sass = require('gulp-sass')(require('sass'));
var config = {
jsPath: './resources/js',
mdPath: './resources/md',
pugPath: './resources/pug',
sassPath: './resources/sass',
}
function css() {
return gulp.src(config.sassPath + '/style.scss')
.pipe(sass({
style: 'compressed',
loadPaths: [
'./resources/sass',
'./node_modules'
],
quietDeps: true
})
.on('error', notify.onError(function (error) {
return "Error: " + error.message;
}))
)
.pipe(gulp.dest('./build/assets/css'));
}
function html() {
var src = config.pugPath + '/finals/**/*.pug',
dst = './build';
return gulp.src(src)
.pipe(changed(dst, {extension: 'html'}))
.pipe(pug({
basedir: config.pugPath + '/include',
filters: {
markdown: (text, options) => {
options = Object.assign({
highlight: (str, lang) => {
if (lang && hljs.getLanguage(lang)) {
try {
return hljs.highlight(str, {language: lang}).value;
} catch (__) {}
}
try {
return hljs.highlightAuto(str).value;
} catch (__) {}
return '';
},
html: true,
langPrefix: 'lang-',
linkify: true,
plugins: [
[md_anchor, {
permalink: md_anchor.permalink.ariaHidden({
placement: 'before'
}),
}],
md_footnote,
[md_toc, {
containerHeaderHtml: '<h1>Contents</h1>',
}],
],
}, options);
return md.render(text, options).body;
}
}
}))
.pipe(minifyhtml())
.pipe(gulp.dest(dst));
}
function js() {
var src = [
'./node_modules/bootstrap/dist/js/bootstrap.min.js',
];
var dst = './build/assets/js';
return gulp.src(src)
.pipe(minifyjs({
ext: {
min: '.min.js'
},
ignoreFiles: ['*.min.js'],
noSource: true,
}))
.pipe(gulp.dest(dst));
}
function img() {
return gulp.src('./resources/img/*')
.pipe(gulp.dest('./build/assets/img'));
}
function pdf() {
return gulp.src('./resources/pdf/*')
.pipe(gulp.dest('./build/assets/pdf'));
}
function fonts() {
gulp.src('./node_modules/@fortawesome/fontawesome-free/webfonts/fa-brands*')
.pipe(gulp.dest('./build/assets/webfonts'));
gulp.src('./node_modules/@fortawesome/fontawesome-free/webfonts/fa-regular*')
.pipe(gulp.dest('./build/assets/webfonts'));
gulp.src('./node_modules/@fortawesome/fontawesome-free/webfonts/fa-solid*')
.pipe(gulp.dest('./build/assets/webfonts'));
gulp.src('./node_modules/academicons/fonts/*')
.pipe(gulp.dest('./build/assets/fonts'));
return gulp.src('./resources/fonts/*')
.pipe(gulp.dest('./build/assets/fonts'));
}
function watch() {
gulp.watch(config.mdPath + '/**/*.md', html);
gulp.watch(config.pugPath + '/**/*.pug', html);
gulp.watch(config.sassPath + '/**/*.scss', css);
}
exports.css = css;
exports.html = html;
exports.img = img;
exports.js = js;
exports.pdf = pdf;
exports.fonts = fonts;
exports.watch = watch;
var build = gulp.parallel(css, html, img, js, pdf, fonts);
gulp.task('build', build);
gulp.task('default', build);
|