-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
62 lines (48 loc) · 1.88 KB
/
gulpfile.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
var gulp = require('gulp');
var markdown = require('gulp-markdown');
var debug = require('gulp-debug');
var tap = require('gulp-tap');
var wrapper = require('gulp-wrapper');
var fs = require('fs');
var frontmatterPattern = /---([\s\S]+)---[\s\S]/;
function getFrontmatter(content) {
var matches = content.match(frontmatterPattern);
if (matches) {
return JSON.parse(matches[1]);
}
return {};
}
function removeFrontmatter(content) {
return content.replace(frontmatterPattern, '');
}
gulp.task('convert', function () {
var header = fs.readFileSync('./aurelia-article-header.html', "utf8");
var footer = fs.readFileSync('./aurelia-article-footer.html', "utf8");
var sqlite3 = require('sqlite3').verbose();
var table = 'searchIndex';
var db = new sqlite3.Database('./aurelia.docset/Contents/Resources/docSet.dsidx');
db.run('DELETE FROM ' + table);
// gulp.src('./doc/article/en-US/a-production-setup.md')
gulp.src('./doc/article/en-US/*.md')
// extract frontmatter
.pipe(tap(function (file) {
var content = file.contents.toString();
var frontmatter = getFrontmatter(content);
file.contents = new Buffer(removeFrontmatter(content));
var sql = "INSERT OR IGNORE INTO searchIndex(name, type, path) VALUES ('" + frontmatter.name + "', 'Guide', '" + file.relative.replace(/\.md/, '.html') + "');";
console.log(sql);
db.run(sql);
return file;
}))
.pipe(markdown({
highlight: function (code) {
return require('highlight.js').highlightAuto(code).value;
}
}))
.pipe(gulp.dest('./aurelia.docset/Contents/Resources/Documents/'))
.pipe(wrapper({
header: header,
footer: footer
}))
.pipe(gulp.dest('./aurelia.docset/Contents/Resources/Documents/'));
});