-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathgulpfile.js
84 lines (69 loc) · 1.99 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
const fs = require("fs");
const del = require("del");
const path = require("path");
const { src, dest, task, watch, series } = require('gulp');
const Gitdown = require('@gnd/gitdown');
const rename = require("gulp-rename");
const debug = require("gulp-debug");
const replace = require("gulp-replace");
task('static', async () => {
if (!fs.existsSync("dist")) {
fs.mkdirSync("dist");
}
await src("static/*").pipe(dest("dist"));
});
task('gitdown', async () => {
if (!fs.existsSync("dist")) {
fs.mkdirSync("dist");
}
const gitdown = Gitdown.readFile(path.join(__dirname, "src", "index.md"));
gitdown.setConfig({
deadlink: {
findDeadURLs: false,
findDeadFragmentIdentifiers: true
},
gitinfo: {
rootUrl: "",
gitPath: gitdown.executionContext()
}
});
gitdown.setLogger(console);
const contents = {
ref: "#user-content-contents",
title: "Back to contents"
};
gitdown.registerHelper("scroll-up", {
compile: (config) => {
const up = {
ref: config.upRef || contents.ref,
title: config.upTitle || contents.title
};
const down = {
ref: config.downRef,
title: config.downTitle
};
if (config.downRef) {
return `<sup>[ [∧](${up.ref}) _${up.title}_ | _${down.title}_ [∨](${down.ref}) ]</sup>`;
} else {
return `<sup>[ [∧](${up.ref}) _${up.title}_ ]</sup>`;
}
}
});
await gitdown.writeFile('dist/_merged.md');
});
task('fix-up', () => {
return src("dist/_merged.md")
.pipe(debug({ title: "merged" }))
.pipe(rename("index.md"))
.pipe(replace("# User Content", "# Data Representation in Solidity"))
.pipe(replace("<a name=\"user-content\"></a>\n", ""))
.pipe(dest("dist"));
});
task('clean:tmp', () => {
return del(["dist/_merged.md"]);
});
task('build', series("static", "gitdown", "fix-up", "clean:tmp"));
task('watch', series(["build", () => {
watch('./src', series(['build']));
}]));
task('default', series('build'));