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-next');
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({
outputStyle: 'compressed',
includePaths: [
'./resources/sass',
'./node_modules'
]
})
.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-sass/assets/javascripts/bootstrap/collapse.js',
'./node_modules/bootstrap-sass/assets/javascripts/bootstrap/transition.js',
'./node_modules/jquery/dist/jquery.slim.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-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);