-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
39 lines (31 loc) · 797 Bytes
/
index.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
var hyperquest = require('hyperquest')
var JSONStream = require('JSONStream')
var through = require('through2')
module.exports = function (source, sink) {
var output = through()
var opts = {
headers: {
'content-type': 'application/json'
}
}
hyperquest(source + '/admin/pages.json')
.pipe(JSONStream.parse('pages.*'))
.pipe(through.obj(write, end))
return output
function write (obj, enc, next) {
if (!obj.title || !obj.body_html) return next()
var post = hyperquest.post(sink + '/admin/pages.json', opts)
post.pipe(output, {end: false})
post.end(JSON.stringify({
page: {
title: obj.title,
body_html: obj.body_html
}
}))
post.on('end', next)
}
function end (next) {
output.end()
next()
}
}