diff --git a/README.md b/README.md index 1b81e9c..a31fb6c 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ Generates a `metadata.xml` file for an EPUB from various online sources, given a few identifiers. -Currently supports the following: +Currently supports the following providers: |Provider|Input| |--------|-----| diff --git a/cli.js b/cli.js index 2652d80..9353020 100755 --- a/cli.js +++ b/cli.js @@ -1,5 +1,5 @@ #!/usr/bin/env node -const generator = require('./index'); +const generator = require("./index"); let ISBN = process.argv[2]; let filepath = process.argv[3]; diff --git a/index.js b/index.js index 4c0396f..24bff8b 100644 --- a/index.js +++ b/index.js @@ -20,16 +20,40 @@ function _convert(data, pretty) { } contents.ele("dc:title", { id: "title" }, data.title); - contents.ele("dc:title", { id: "subtitle" }, data.description); - contents.ele( - "meta", - { refines: "#subtitle", property: "title-type" }, - "subtitle" - ); + + if (undefined !== data.description) { + contents.ele("dc:title", { id: "subtitle" }, data.description); + contents.ele( + "meta", + { refines: "#subtitle", property: "title-type" }, + "subtitle" + ); + } contents.ele("dc:language", {}, data.language); contents.ele("dc:publisher", {}, data.publisher); + let date = new Date(Date.parse(data.publishedDate)); + + function pad(number) { + if (number < 10) { + return "0" + number; + } + return number; + } + + let epubDate = + date.getUTCFullYear() + + "-" + + pad(date.getUTCMonth() + 1) + + "-" + + pad(date.getUTCDate()); + + contents.ele("dc:date", {}, epubDate); + if (undefined !== data.imageLinks.cover) { + contents.ele("dc:identifier", { id: "cover-url" }, data.imageLinks.cover); + } + let blob = contents.end({ pretty: pretty }); return blob; } diff --git a/openlibrary.js b/openlibrary.js index 9aa14ea..9be158f 100644 --- a/openlibrary.js +++ b/openlibrary.js @@ -17,10 +17,7 @@ module.exports = { pageCount: book.details.number_of_pages, printType: "BOOK", categories: [], - imageLinks: { - smallThumbnail: book.thumbnail_url, - thumbnail: book.thumbnail_url - }, + imageLinks: {}, previewLink: book.preview_url, infoLink: book.info_url }; @@ -51,6 +48,20 @@ module.exports = { }); } + if (undefined !== book.details.cover) { + if (undefined !== book.details.cover.small) { + standardBook.imageLinks.smallThumbnail = book.details.cover.small; + } + + if (undefined !== book.details.cover.large) { + standardBook.imageLinks.cover = book.details.cover.large; + } + + if (undefined !== book.details.cover.medium) { + standardBook.imageLinks.thumnail = book.details.cover.medium; + } + } + if (book.details.publishers) { standardBook.publisher = book.details.publishers[0]; } else {