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