-
-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathgulpfile.js
61 lines (49 loc) · 1.42 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
'use strict';
// This file is only for generating the docs
// No need to use any of this if working on the main website
const { src, dest, series } = require('gulp');
const pump = require('pump');
const through2 = require('through2');
const frontMatter = require('gray-matter');
const download = require('github-download-directory');
// Exports for task registration
exports.default = series(fetchDocs, convertComments);
const owner = 'gulpjs';
const repo = 'gulp';
const directory = 'docs';
const outDirectory = 'converted-docs';
const fmOptions = {
delimiters: ['<!-- front-matter', '-->']
};
function fetchDocs() {
return download(owner, repo, directory, { sha: "master" });
}
function convertComments(cb) {
pump([
// Only process markdown files in the directory we fetched
src('**/*.md', { cwd: directory }),
pluginless(convertToDocusaurus),
// Overwrite the markdown files we fetched
dest(outDirectory)
], cb)
}
/* utils */
function convertToDocusaurus(file) {
var config = frontMatter(file.contents, fmOptions);
if (!config.data.id) {
console.error(`File missing front-matter. Path: ${file.path}`);
return; // Filter out any file without frontmatter
}
file.contents = Buffer.from(config.stringify());
return file;
}
function pluginless(fn) {
return through2.obj(handler);
function handler(file, _, cb) {
try {
cb(null, fn(file));
} catch(err) {
cb(err);
}
}
}