diff options
author | Camil Staps | 2021-06-23 09:25:36 +0200 |
---|---|---|
committer | Camil Staps | 2021-06-23 09:25:36 +0200 |
commit | 9b8045e9ff6fc02dde1f0e14ecb419d852352633 (patch) | |
tree | fd0a206697ca520079f7737f9f669c80787ffc35 /gulpfile.js | |
parent | Replace menuItem mixin in sidebar layout with single menu mixin (diff) |
Setup infrastructure for articles written in markdown
Diffstat (limited to 'gulpfile.js')
-rw-r--r-- | gulpfile.js | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/gulpfile.js b/gulpfile.js index f6eef2d..824a788 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -1,11 +1,14 @@ var gulp = require('gulp'), changed = require('gulp-changed'), + hljs = require('highlight.js'), + md = require('jstransformer')(require('jstransformer-markdown-it')), minifyhtml = require('gulp-minify-html'), notify = require('gulp-notify'), pug = require('gulp-pug-3'), sass = require('gulp-sass-next'); var config = { + mdPath: './resources/md', pugPath: './resources/pug', sassPath: './resources/sass', } @@ -33,7 +36,29 @@ function html() { return gulp.src(src) .pipe(changed(dst, {extension: 'html'})) .pipe(pug({ - basedir: config.pugPath + '/include' + 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 ''; + }, + langPrefix: 'lang-', + linkify: true, + }, options); + return md.render(text, options).body; + } + } })) .pipe(minifyhtml()) .pipe(gulp.dest(dst)); @@ -59,6 +84,7 @@ function fonts() { } function watch() { + gulp.watch(config.mdPath + '/**/*.md', html); gulp.watch(config.pugPath + '/**/*.pug', html); gulp.watch(config.sassPath + '/**/*.scss', css); } |