-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathprocessor.js
34 lines (29 loc) · 884 Bytes
/
processor.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
const Maybe = require('folktale/maybe')
const Task = require('folktale/concurrency/task')
const Parser = require('markdown-parser')
const { File, Dir } = require('./files')
const parseTask = Task.fromNodeback((content, cb) => new Parser().parse(content, cb))
// Config
// -> List (FileType String Bool)
// -> Task ( List ( FileType String Markdown ) )
module.exports = config => tree =>
tree.traverse(Task.of,
file => {
const fileResult =
file.chain(
file => parseMarkdown(file),
([ path, x ]) => Task.of(Dir(path, x))
)
return fileResult
}
)
// [ path, content ] -> Task File
const parseMarkdown = ([ path, content ]) => {
if (!content.length) {
const file = File(path, Maybe.Nothing())
return Task.of(file)
}
return parseTask(content)
.map(Maybe.Just)
.map(parsed => File(path, parsed))
}