This repository was archived by the owner on Dec 7, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.js
More file actions
80 lines (68 loc) · 2.65 KB
/
gulpfile.js
File metadata and controls
80 lines (68 loc) · 2.65 KB
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
var gulp = require('gulp');
var del = require('del');
var sass = require('gulp-sass');
var frontMatter = require('gulp-front-matter');
var markdown = require('gulp-markdown');
var layout = require('gulp-layout');
var fileinclude = require('gulp-file-include');
var dom = require('gulp-dom');
var replace = require('gulp-replace');
gulp.task('clean', function() {
return del(['./pages/**', '!./pages']);
});
gulp.task('content_markdown', function() {
return gulp.src('./src/content/**/[^%]*(*.md|*.markdown)')
.pipe(fileinclude({
prefix: '@@',
basepath: '@file'
}))
.pipe(frontMatter())
.pipe(markdown())
// todo: find a nicer way to implement this and add the footnote text as title to the refering link
.pipe(replace(/\[\^(\w+)\]:/g, '<a name="footnote-$1" href="#footnote-referer-$1">$1</a>:')) // replace footnoe
.pipe(replace(/\[\^(\w+)\]/g, '<sup><a name="footnote-referer-$1" href="#footnote-$1">$1</a></sup>')) // replace link refering to footnote
.pipe(layout(function(file) {
var options = file.frontMatter;
if (!options.layout) options.layout = 'layout.html';
options.layout = './src/template/' + options.layout
if (!options.engine) options.engine = 'handlebars';
if (!options.title) console.warn("No title set for file", file.path);
return options;
}))
.pipe(dom(function() {
// Find all <p>s which contain only images and add the 'images' class to them
var ps = this.querySelector('article').querySelectorAll('p');
for (i = 0; i < ps.length; i++) { // For some reason there's no forEach available
var p = ps[i];
if (p.children.length > 0) {
var childrenAreAllImages = true;
for (c = 0; c < p.children.length; c++) {
if (p.children[c].tagName != 'IMG') childrenAreAllImages = false;
}
if (childrenAreAllImages) {
p.classList.add("images");
}
}
}
return this;
}))
.pipe(gulp.dest('./pages'));
});
gulp.task('content_other', function() {
return gulp.src([
'./src/content/**/[^%]*',
'!./src/content/**/[^%]*(*.md|*.markdown)'])
.pipe(gulp.dest('./pages'));
});
gulp.task('content', ['content_markdown', 'content_other']);
gulp.task('template_sass', function(){
return gulp.src('./src/template/scss/styles.scss')
.pipe(sass()) // Converts Sass to CSS with gulp-sass
.pipe(gulp.dest('./pages/css'));
});
gulp.task('template_images', function() {
return gulp.src('./src/template/images/**/*')
.pipe(gulp.dest('./pages/images'))
});
gulp.task('template', ['template_sass', 'template_images']);
gulp.task('build', [ 'template', 'content' ]);