This repository was archived by the owner on Jun 27, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathconverter.js
More file actions
45 lines (41 loc) · 1.96 KB
/
converter.js
File metadata and controls
45 lines (41 loc) · 1.96 KB
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
var Converter = function (xml, siteTitle) {
this.GetZippedHtmlFiles = function (callback) {
//TODO: Note this creates two nested folders called html which isn't the ideal file structure...
var topNode = xml.find('body');
// Ignore the top node if there is only one at that level and it matches the site title and it doesn't have a content node
if (topNode.children().length == 1 &&
stripText(siteTitle) == stripText(topNode.children().first().attr('text')) &&
topNode.children().first().children('[text=Content]').length == 0) {
topNode = topNode.children().first();
}
var bodyNode = new Outline(topNode, '', '', 'html', []);
var htmlPages = bodyNode.process(siteTitle, new HtmlGenerator());
var zip = new JSZip();
htmlPages.forEach(function (page) {
zip.file(page.filePath, page.content);
});
var imageFileNames = ['bar-graph', 'image' ,'line-graph', 'pie-chart', 'quote', 'text', 'video'];
//Import javascript and stylesheets
async.series([
function (callback) {
addExistingFile(zip, chrome.extension.getURL('resources/stylesheets/style.css'), 'stylesheets/style.css', callback);
addExistingFile(zip, chrome.extension.getURL('resources/stylesheets/empty.css'), 'stylesheets/custom.css', callback);
}
].concat(imageFileNames.map(function(imageFileName) {
return function (callback) {
addExistingFile(zip, chrome.extension.getURL('resources/images/' + imageFileName + '.png'), 'images/' + imageFileName + '.png', callback);
};
})), function () {
callback(zip.generate({ type: 'blob' }));
});
};
function addExistingFile(zip, filePath, zipPath, callback) {
JSZipUtils.getBinaryContent(filePath, function (err, data) {
if (err) {
console.log('File failed to load', filePath, err);
}
zip.file(zipPath, data);
callback(null, true);
});
}
}