|
|
|
@ -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 });
|
|
|
|
|