-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.js
40 lines (19 loc) · 890 Bytes
/
test.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
var epubed = require('./lib/epub-editor');
var epubFile = process.argv[2];
epubed.open(epubFile, function (err, container) {
// add a js subdir if it doesn't exist
if(err) {
throw err;
}
container.zip.addDirectory('OEBPS/js');
// add a JS file to the manifest
container.zip.addFile('OEBPS/js/main.js', new Buffer('alert("all good");'));
// add another HTML file that references the JS
container.zip.addFile('OEBPS/script-test.html', new Buffer('<html><head/><body><script src="js/main.js"></script></body></html>'));
// add a spine ref for the script, at the end (dont specify position in second arg)
container.toc.addSpineItem('OEBPS/script-test.html');
// add a navpoint to the ncx, at specified position (by playOrder)
container.toc.addNavPoint('OEBPS/script-test.html', 3);
// write all changes
container.writeChanges(epubFile+'-modified.zip');
});