Adds support for cover image and title
This commit is contained in:
parent
e4849f728b
commit
7906f151e6
12
generate.js
12
generate.js
|
@ -13,9 +13,12 @@ const getArticle = async url => {
|
|||
}
|
||||
};
|
||||
|
||||
module.exports = (url, epubPath, language="en-US") => {
|
||||
module.exports = (url, epubPath, title, coverURL, language="en-US") => {
|
||||
getArticle(url).then(res => {
|
||||
let xml = `<dc:title id="epub-title-1">${res.title}</dc:title>
|
||||
|
||||
title = title ? title : res.title;
|
||||
|
||||
let xml = `<dc:title id="epub-title-1">${title}</dc:title>
|
||||
<dc:date>${res.published}</dc:date>
|
||||
<dc:language>${language}</dc:language>
|
||||
<dc:identifier>${url}</dc:identifier>
|
||||
|
@ -26,10 +29,9 @@ module.exports = (url, epubPath, language="en-US") => {
|
|||
|
||||
fs.writeFileSync(html, res.content);
|
||||
fs.writeFileSync(metadata, xml);
|
||||
const imageUrl = coverURL ? coverURL : res.image;
|
||||
|
||||
const imageUrl = res.image;
|
||||
|
||||
const dl = new DownloaderHelper(res.image, "/tmp", {
|
||||
const dl = new DownloaderHelper(imageUrl, "/tmp", {
|
||||
fileName: "epub-to-image.jpg"
|
||||
});
|
||||
|
||||
|
|
18
index.js
18
index.js
|
@ -3,7 +3,7 @@ var argv = require("yargs").argv;
|
|||
const generateEPUB = require("./generate");
|
||||
|
||||
require("yargs") // eslint-disable-line
|
||||
.usage("$0 --output [output] <url>")
|
||||
.usage("$0 --output [output] --title [title] <url>")
|
||||
.help("h")
|
||||
.command(
|
||||
"$0 <url>",
|
||||
|
@ -20,6 +20,18 @@ require("yargs") // eslint-disable-line
|
|||
default: "url-to-epub.epub",
|
||||
description: "Output file to save EPUB"
|
||||
})
|
||||
.option("title", {
|
||||
alias: "t",
|
||||
type: "string",
|
||||
default: null,
|
||||
description:
|
||||
"Title of the book, if not the same as the page title"
|
||||
})
|
||||
.option("cover-url", {
|
||||
type: "string",
|
||||
default: null,
|
||||
description: "Image URL to download as cover"
|
||||
})
|
||||
.option("language", {
|
||||
alias: "l",
|
||||
type: "string",
|
||||
|
@ -261,11 +273,11 @@ require("yargs") // eslint-disable-line
|
|||
]
|
||||
})
|
||||
.example(
|
||||
'$0 -o articulated-restraint.epub "https://www.tor.com/2019/02/06/articulated-restraint-mary-robinette-kowal/"'
|
||||
'$0 --title "Articulated Restraint" -o articulated-restraint.epub "https://www.tor.com/2019/02/06/articulated-restraint-mary-robinette-kowal/"'
|
||||
)
|
||||
.demandOption(["url"]);
|
||||
},
|
||||
argv => {
|
||||
generateEPUB(argv.url, argv.output);
|
||||
generateEPUB(argv.url, argv.output, argv.title, argv['cover-url'], argv.language);
|
||||
}
|
||||
).argv;
|
Loading…
Reference in New Issue