Fixes OPF file format and cover URLs
This commit is contained in:
parent
85c9ef2ed6
commit
191557eae7
33
index.js
33
index.js
|
@ -3,12 +3,17 @@ const fs = require("fs");
|
|||
const XML = require("xmlbuilder");
|
||||
|
||||
function _convert(data, pretty) {
|
||||
let contents = XML.create("metadata", {
|
||||
"xmlns:dc": "http://purl.org/dc/elements/1.1/"
|
||||
});
|
||||
let contents = XML.create("package");
|
||||
contents.att("unique-identifier", "uuid_id")
|
||||
contents.att('xmlns', 'http://www.idpf.org/2007/opf')
|
||||
|
||||
let metadata = contents.ele("metadata");
|
||||
metadata.att("xmlns:opf","http://www.idpf.org/2007/opf")
|
||||
metadata.att("xmlns:dc","http://purl.org/dc/elements/1.1/")
|
||||
|
||||
for (let key in data.industryIdentifiers) {
|
||||
let d = data.industryIdentifiers[key];
|
||||
contents.ele(
|
||||
metadata.ele(
|
||||
"dc:identifier",
|
||||
{ "opf:scheme": d["type"] },
|
||||
d["identifier"][0]
|
||||
|
@ -16,22 +21,22 @@ function _convert(data, pretty) {
|
|||
}
|
||||
|
||||
for (let i in data.authors) {
|
||||
contents.ele("dc:creator", { "opf:role": "aut" }, data.authors[i]);
|
||||
metadata.ele("dc:creator", { "opf:role": "aut" }, data.authors[i]);
|
||||
}
|
||||
|
||||
contents.ele("dc:title", { id: "title" }, data.title);
|
||||
metadata.ele("dc:title", { id: "title" }, data.title);
|
||||
|
||||
if (undefined !== data.description) {
|
||||
contents.ele("dc:title", { id: "subtitle" }, data.description);
|
||||
contents.ele(
|
||||
metadata.ele("dc:title", { id: "subtitle" }, data.description);
|
||||
metadata.ele(
|
||||
"meta",
|
||||
{ refines: "#subtitle", property: "title-type" },
|
||||
"subtitle"
|
||||
);
|
||||
}
|
||||
|
||||
contents.ele("dc:language", {}, data.language);
|
||||
contents.ele("dc:publisher", {}, data.publisher);
|
||||
metadata.ele("dc:language", {}, data.language);
|
||||
metadata.ele("dc:publisher", {}, data.publisher);
|
||||
|
||||
let date = new Date(Date.parse(data.publishedDate));
|
||||
|
||||
|
@ -49,9 +54,11 @@ function _convert(data, pretty) {
|
|||
"-" +
|
||||
pad(date.getUTCDate());
|
||||
|
||||
contents.ele("dc:date", {}, epubDate);
|
||||
if (undefined !== data.imageLinks.cover) {
|
||||
contents.ele("dc:identifier", { id: "cover-url" }, data.imageLinks.cover);
|
||||
metadata.ele("dc:date", {}, epubDate);
|
||||
|
||||
|
||||
if (undefined !== data.imageLinks.large) {
|
||||
metadata.ele("dc:identifier", { id: "cover-url" }, data.imageLinks.large);
|
||||
}
|
||||
|
||||
let blob = contents.end({ pretty: pretty });
|
||||
|
|
|
@ -48,18 +48,14 @@ module.exports = {
|
|||
});
|
||||
}
|
||||
|
||||
if (undefined !== book.details.cover) {
|
||||
if (undefined !== book.details.cover.small) {
|
||||
standardBook.imageLinks.smallThumbnail = book.details.cover.small;
|
||||
}
|
||||
console.log(JSON.stringify(book.details));
|
||||
|
||||
if (undefined !== book.details.cover.large) {
|
||||
standardBook.imageLinks.cover = book.details.cover.large;
|
||||
}
|
||||
if (undefined !== book.details.covers) {
|
||||
let coverId = book.details.covers[0];
|
||||
|
||||
if (undefined !== book.details.cover.medium) {
|
||||
standardBook.imageLinks.thumnail = book.details.cover.medium;
|
||||
}
|
||||
standardBook.imageLinks.small = `https://covers.openlibrary.org/b/id/${coverId}-S.jpg`;
|
||||
standardBook.imageLinks.medium = `https://covers.openlibrary.org/b/id/${coverId}-M.jpg`;
|
||||
standardBook.imageLinks.large = `https://covers.openlibrary.org/b/id/${coverId}-L.jpg`;
|
||||
}
|
||||
|
||||
if (book.details.publishers) {
|
||||
|
|
Loading…
Reference in New Issue