-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdocs-plugin.js
56 lines (43 loc) · 1.36 KB
/
docs-plugin.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
"use strict";
module.exports = {
name: 'Documentation plugin',
setup(build) {
build.onResolve({ filter: /\.md/ }, args => {
const path = require('path')
return { path: path.join(process.cwd(), 'documentation', args.path) }
})
build.onLoad({ filter: /\.md$/ }, args => {
const fs = require('fs')
, MarkdownIt = require('markdown-it')
, { version } = require('./package.json')
, md = new MarkdownIt({ html: true })
const replacements = [
[/%%VERSION%%/g, version],
[/%%VERSION-PREFIXED%%/g, `dredge-${version}`],
[/%%ZIP-FILENAME%%/g, `dredge-${version}.zip`],
[/%%PROJECT-DIR%%/g, `dredge-${version}`],
[/%%PROJECT-DATA-DIR%%/g, `dredge-${version}/data`],
]
md.use(require('markdown-it-attrs'))
let markdown = fs.readFileSync(args.path).toString()
replacements.forEach(([pattern, subst]) => {
markdown = markdown.replace(pattern, subst)
})
const contents = md.render(markdown)
return {
contents,
loader: 'text',
}
})
},
}
/*
return through(function (buf, enc, next) {
this.push(buf.toString('utf-8').replace(REGEX, (match, filename) => {
let markdown = fs.readFileSync('./documentation/' + filename).toString()
return JSON.stringify(contents)
}))
next()
})
}
*/