|
@@ -0,0 +1,41 @@
|
|
|
+import Yargs from 'yargs';
|
|
|
+import { default as Epub } from 'epub-gen'
|
|
|
+import { Readability } from '@mozilla/readability'
|
|
|
+import { JSDOM } from 'jsdom';
|
|
|
+import { open } from 'node:fs/promises';
|
|
|
+
|
|
|
+const options = Yargs(process.argv.slice(2))
|
|
|
+ .usage("Usage: -u <path> -o <path>")
|
|
|
+ .option("u", { alias: "urls", describe: "File containing your list of urls", type: "string", demandOption: true })
|
|
|
+ .option("o", { alias: "output", describe: "Output file", type: "string", demandOption: true })
|
|
|
+ .option("t", { alias: "title", describe: "Ebook title", type: "string", default: "My Epub" })
|
|
|
+ .option("c", { alias: "cover", describe: "Ebook cover file", type: "string", default: "./rotocalco.jpeg" })
|
|
|
+ .option("a", { alias: "author", describe: "Ebook Author's name", type: "string", default: "Rotocalco" })
|
|
|
+ .option("p", { alias: "publisher", describe: "Ebook Publisher's name", type: "string", default: "Rotocalco" })
|
|
|
+ .argv;
|
|
|
+
|
|
|
+
|
|
|
+let content = []
|
|
|
+
|
|
|
+console.log(`Reading urls file ${options.urls}`)
|
|
|
+
|
|
|
+const file = await open(options.urls);
|
|
|
+for await (const pageUri of file.readLines()) {
|
|
|
+ console.log(pageUri);
|
|
|
+ const response = await fetch(pageUri)
|
|
|
+ const pageContent = await response.text()
|
|
|
+ const doc = new JSDOM(pageContent, { url: pageUri })
|
|
|
+ const reader = new Readability(doc.window.document)
|
|
|
+ const article = reader.parse()
|
|
|
+ content.push({title: article.title, data: article.content })
|
|
|
+}
|
|
|
+
|
|
|
+const epubOpts = {
|
|
|
+ title: options.title,
|
|
|
+ author: options.author,
|
|
|
+ cover: options.cover,
|
|
|
+ publisher: options.publisher,
|
|
|
+ content: content,
|
|
|
+};
|
|
|
+
|
|
|
+new Epub(epubOpts, options.output);
|