Added cover to Metadata

If the meta tag contains the "cover" keyword, add "cover" to the
metadata with the content as the value
This commit is contained in:
Colin 2017-04-26 07:32:14 -05:00
parent b88fa034fc
commit 9a8d11aeda

14
epub.js
View File

@ -9,7 +9,7 @@ try {
} catch (err) { } catch (err) {
// Mock zipfile using pure-JS adm-zip: // Mock zipfile using pure-JS adm-zip:
var AdmZip = require('adm-zip'); var AdmZip = require('adm-zip');
var ZipFile = function(filename) { var ZipFile = function(filename) {
this.admZip = new AdmZip(filename); this.admZip = new AdmZip(filename);
this.names = this.admZip.getEntries().map(function(zipEntry) { this.names = this.admZip.getEntries().map(function(zipEntry) {
@ -385,7 +385,7 @@ EPub.prototype.parseMetadata = function (metadata) {
break; break;
} }
} }
var metas = metadata['meta'] || {}; var metas = metadata['meta'] || {};
Object.keys(metas).forEach(function(key) { Object.keys(metas).forEach(function(key) {
var meta = metas[key]; var meta = metas[key];
@ -396,6 +396,10 @@ EPub.prototype.parseMetadata = function (metadata) {
if (meta['#'] && meta['@'].property) { if (meta['#'] && meta['@'].property) {
this.metadata[meta['@'].property] = meta['#']; this.metadata[meta['@'].property] = meta['#'];
} }
if(meta.name && meta.name =="cover"){
this.metadata[meta.name] = meta.content;
}
}, this); }, this);
}; };
@ -522,7 +526,7 @@ EPub.prototype.walkNavMap = function (branch, path, id_list, level) {
var title = ''; var title = '';
if (branch[i].navLabel && typeof branch[i].navLabel.text == 'string') { 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(); '' : (branch[i].navLabel && branch[i].navLabel.text || branch[i].navLabel || "").trim();
} }
var order = Number(branch[i]["@"] && branch[i]["@"].playOrder || 0); 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_) { EPub.prototype.readFile = function(filename, options, callback_) {
var callback = arguments[arguments.length - 1]; var callback = arguments[arguments.length - 1];
if (util.isFunction(options) || !options) { if (util.isFunction(options) || !options) {
this.zip.readFile(filename, callback); this.zip.readFile(filename, callback);
} else if (util.isString(options)) { } else if (util.isString(options)) {
@ -762,4 +766,4 @@ EPub.prototype.readFile = function(filename, options, callback_) {
// Expose to the world // Expose to the world
module.exports = EPub; module.exports = EPub;