forked from jondashkyle/nanocontent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
transform.js
54 lines (43 loc) · 1.37 KB
/
transform.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
var staticModule = require('static-module')
var through = require('through2')
var path = require('path')
var hypha = require('.')
module.exports = transform
function transform (filename) {
if (/\.json$/.test(filename)) return through()
var vars = {
__filename: filename,
__dirname: path.dirname(filename)
}
var sm = staticModule({
hypha: {
readPageSync: function (pathPage, opts) {
opts = opts || { }
opts.pathRoot = opts.pathRoot || vars.__dirname
var pathDir = path.isAbsolute(pathPage) ? pathPage : path.join(vars.__dirname, pathPage)
var pageSync = hypha.readPageSync(pathDir, opts)
var stream = through()
stream.push(JSON.stringify(pageSync, { }, 2))
stream.push(null)
return stream
},
readSiteSync: function readDir (pathSite, opts) {
opts = opts || { }
opts.pathRoot = opts.pathRoot || vars.__dirname
opts.onFile = function (pathFile) {
sm.emit('file', pathFile)
}
var pathDir = path.isAbsolute(pathSite) ? pathSite : path.join(vars.__dirname, pathSite)
var siteSync = hypha.readSiteSync(pathDir, opts)
var stream = through()
stream.push(JSON.stringify(siteSync, { }, 2))
stream.push(null)
return stream
}
}
}, {
vars: vars,
varModules: { path: path }
})
return sm
}