forked from mauriciopoppe/function-plot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsite.cjs
64 lines (57 loc) · 1.58 KB
/
site.cjs
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
/**
* Created by mauricio on 4/9/15.
*/
const fs = require('fs')
const dox = require('dox')
const _ = require('lodash')
const pug = require('pug')
const md = require('markdown-it')({
html: true,
linkify: true,
typographer: true
})
function renderExamples() {
const file = fs.readFileSync('./site/js/site.js', { encoding: 'utf-8' })
const comments = dox.parseComments(file)
const parsed = comments
.map(function (c) {
let ids = c.code.match(/target:\s*'(.*)'/g)
if (ids) {
ids = ids.map(function (str) {
return /#[0-9a-zA-Z-]*/.exec(str)[0].substr(1)
})
}
let comment = c.description.full
let experimental
if (_.find(c.tags, { type: 'experimental' })) {
experimental = true
}
let additionalDOM = _.find(c.tags, { type: 'additionalDOM' })
if (additionalDOM) {
additionalDOM = additionalDOM.string
}
comment = comment.replace(/<br\s*\/>/g, ' ')
return {
comment,
experimental,
code: c.code,
additionalDOM,
ids
}
})
.filter(function (entry) {
return entry.ids
})
const output = fs.createWriteStream('./site/partials/examples.html')
output.write(pug.compileFile('./site/tpl/examples.pug')({ comments: parsed }))
output.end()
}
function renderRecipes() {
const file = fs.readFileSync('./site/tpl/recipes.md', { encoding: 'utf-8' })
const result = md.render(file)
const output = fs.createWriteStream('./site/partials/recipes.html')
output.write(result)
output.end()
}
renderExamples()
renderRecipes()