From 9a8d11aeda5a5ade12e12c1a4c03d34ebd2e6fcf Mon Sep 17 00:00:00 2001 From: Colin Date: Wed, 26 Apr 2017 07:32:14 -0500 Subject: [PATCH] Added cover to Metadata If the meta tag contains the "cover" keyword, add "cover" to the metadata with the content as the value --- epub.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/epub.js b/epub.js index 246918f..7332e94 100644 --- a/epub.js +++ b/epub.js @@ -9,7 +9,7 @@ try { } catch (err) { // Mock zipfile using pure-JS adm-zip: var AdmZip = require('adm-zip'); - + var ZipFile = function(filename) { this.admZip = new AdmZip(filename); this.names = this.admZip.getEntries().map(function(zipEntry) { @@ -385,7 +385,7 @@ EPub.prototype.parseMetadata = function (metadata) { break; } } - + var metas = metadata['meta'] || {}; Object.keys(metas).forEach(function(key) { var meta = metas[key]; @@ -396,6 +396,10 @@ EPub.prototype.parseMetadata = function (metadata) { if (meta['#'] && meta['@'].property) { this.metadata[meta['@'].property] = meta['#']; } + + if(meta.name && meta.name =="cover"){ + this.metadata[meta.name] = meta.content; + } }, this); }; @@ -522,7 +526,7 @@ EPub.prototype.walkNavMap = function (branch, path, id_list, level) { var title = ''; if (branch[i].navLabel && typeof branch[i].navLabel.text == 'string') { - title = branch[i].navLabel && branch[i].navLabel.text || branch[i].navLabel===branch[i].navLabel ? + title = branch[i].navLabel && branch[i].navLabel.text || branch[i].navLabel===branch[i].navLabel ? '' : (branch[i].navLabel && branch[i].navLabel.text || branch[i].navLabel || "").trim(); } var order = Number(branch[i]["@"] && branch[i]["@"].playOrder || 0); @@ -743,7 +747,7 @@ EPub.prototype.getFile = function (id, callback) { EPub.prototype.readFile = function(filename, options, callback_) { var callback = arguments[arguments.length - 1]; - + if (util.isFunction(options) || !options) { this.zip.readFile(filename, callback); } else if (util.isString(options)) { @@ -762,4 +766,4 @@ EPub.prototype.readFile = function(filename, options, callback_) { // Expose to the world -module.exports = EPub; \ No newline at end of file +module.exports = EPub;