forked from ramda/ramda.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
publish.js
137 lines (119 loc) · 3.03 KB
/
publish.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
const fs = require('fs');
const Path = require('path');
const {
applySpec,
chain,
defaultTo,
filter,
head,
join,
map,
path,
pipe,
prop,
propEq,
replace,
split,
} = require('ramda');
const handlebars = require('handlebars');
const hljs = require('highlight.js');
const helper = require('jsdoc/util/templateHelper');
const marked = require('marked');
const mardownToHtml = function(mdstr) {
return marked.parse(mdstr);
}
const version = require('./package.json').devDependencies.ramda
const prettifyCode = pipe(
join('\n'),
replace(/^[ ]{5}/gm, ''),
s => hljs.highlight('javascript', s).value
)
const prettifySig = pipe(
replace(/[.][.][.]/g, '\u2026'),
replace(/->/g, '\u2192')
)
// simplifySee :: Array String -> Array String
//
// Handles any combination of comma-separated and multi-line @see annotations.
const simplifySee = pipe(chain(split(/\s*,\s*/)), map(replace(/^R[.]/, '')))
const titleFilter = pipe(propEq('title'), filter)
const valueProp = chain(prop('value'))
const simplifyData = applySpec({
aka: pipe(
prop('tags'),
titleFilter('aka'),
valueProp,
chain(split(/,\s*/))
),
category: pipe(
prop('tags'),
titleFilter('category'),
valueProp,
head,
defaultTo('')
),
deprecated: pipe(prop('deprecated'), defaultTo('')),
description: pipe(
prop('description'),
defaultTo(''),
mardownToHtml
),
example: pipe(
prop('examples'),
defaultTo(''),
prettifyCode
),
name: pipe(prop('name'), defaultTo('')),
params: pipe(
prop('params'),
defaultTo([]),
map(applySpec({
description: pipe(
prop('description'),
defaultTo(''),
mardownToHtml
),
name: pipe(prop('name'), defaultTo('')),
type: pipe(path(['type', 'names', 0]), defaultTo(''))
}))
),
returns: {
description: pipe(path(['returns', 0, 'description']), defaultTo('')),
type: pipe(path(['returns', 0, 'type', 'names', 0]), defaultTo(''))
},
see: pipe(
prop('see'),
defaultTo(''),
simplifySee
),
sigs: pipe(
prop('tags'),
titleFilter('sig'),
valueProp,
map(prettifySig)
),
since: pipe(prop('since'), defaultTo('')),
typedefns: pipe(
prop('tags'),
titleFilter('typedefn'),
valueProp,
map(prettifySig)
)
})
exports.publish = (data, opts) => {
const templateFile = Path.resolve(opts.destination, 'index.html.handlebars')
const templateContent = fs.readFileSync(templateFile, {encoding: 'utf8'})
const docs = helper.prune(data)()
.order('name, version, since')
.filter({kind: ['function', 'constant']})
.get()
.filter(x => x.access !== 'private')
.map(simplifyData)
const context = {
docs: docs,
version: version
}
const outputContent = handlebars.compile(templateContent)(context)
const outputFile = Path.resolve(opts.destination, 'index.html')
fs.writeFileSync(outputFile, outputContent, {encoding: 'utf8'});
}