General improvements
This commit is contained in:
parent
b97fa62e7c
commit
a46bb80ac8
12
generate.js
12
generate.js
|
@ -3,6 +3,8 @@ const tempFile = require("tempfile");
|
||||||
const nodePandoc = require("node-pandoc-promise");
|
const nodePandoc = require("node-pandoc-promise");
|
||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
const { DownloaderHelper } = require("node-downloader-helper");
|
const { DownloaderHelper } = require("node-downloader-helper");
|
||||||
|
const path = require('path');
|
||||||
|
const slugify = require('slugify');
|
||||||
|
|
||||||
const getArticle = async url => {
|
const getArticle = async url => {
|
||||||
try {
|
try {
|
||||||
|
@ -18,11 +20,16 @@ module.exports = (url, epubPath, title, coverURL, language="en-US") => {
|
||||||
|
|
||||||
title = title ? title : res.title;
|
title = title ? title : res.title;
|
||||||
|
|
||||||
|
epubPath = epubPath ? epubPath : slugify(path.basename(url)) + '.epub';
|
||||||
|
|
||||||
let xml = `<dc:title id="epub-title-1">${title}</dc:title>
|
let xml = `<dc:title id="epub-title-1">${title}</dc:title>
|
||||||
<dc:date>${res.published}</dc:date>
|
<dc:date>${res.published}</dc:date>
|
||||||
<dc:language>${language}</dc:language>
|
<dc:language>${language}</dc:language>
|
||||||
<dc:identifier>${url}</dc:identifier>
|
<dc:identifier>${url}</dc:identifier>
|
||||||
<dc:creator id="epub-creator-1" opf:role="aut">${res.author}</dc:creator>`;
|
<dc:source>${url}</dc:source>
|
||||||
|
<dc:description>${res.description}</dc:description>
|
||||||
|
<dc:publisher>${res.source}</dc:publisher>
|
||||||
|
<dc:creator opf:role="aut">${res.author}</dc:creator>`;
|
||||||
|
|
||||||
let html = tempFile(".html");
|
let html = tempFile(".html");
|
||||||
let metadata = tempFile(".xml");
|
let metadata = tempFile(".xml");
|
||||||
|
@ -32,7 +39,8 @@ module.exports = (url, epubPath, title, coverURL, language="en-US") => {
|
||||||
const imageUrl = coverURL ? coverURL : res.image;
|
const imageUrl = coverURL ? coverURL : res.image;
|
||||||
|
|
||||||
const dl = new DownloaderHelper(imageUrl, "/tmp", {
|
const dl = new DownloaderHelper(imageUrl, "/tmp", {
|
||||||
fileName: "epub-to-image.jpg"
|
fileName: "epub-to-image.jpg",
|
||||||
|
override: true
|
||||||
});
|
});
|
||||||
|
|
||||||
dl.start();
|
dl.start();
|
||||||
|
|
2
index.js
2
index.js
|
@ -17,7 +17,7 @@ require("yargs") // eslint-disable-line
|
||||||
.option("output", {
|
.option("output", {
|
||||||
alias: "o",
|
alias: "o",
|
||||||
type: "string",
|
type: "string",
|
||||||
default: "url-to-epub.epub",
|
default: false,
|
||||||
description: "Output file to save EPUB"
|
description: "Output file to save EPUB"
|
||||||
})
|
})
|
||||||
.option("title", {
|
.option("title", {
|
||||||
|
|
|
@ -947,6 +947,11 @@
|
||||||
"resolved": "https://registry.npmjs.org/set-blocking/-/set-blocking-2.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/set-blocking/-/set-blocking-2.0.0.tgz",
|
||||||
"integrity": "sha1-BF+XgtARrppoA93TgrJDkrPYkPc="
|
"integrity": "sha1-BF+XgtARrppoA93TgrJDkrPYkPc="
|
||||||
},
|
},
|
||||||
|
"slugify": {
|
||||||
|
"version": "1.3.6",
|
||||||
|
"resolved": "https://registry.npmjs.org/slugify/-/slugify-1.3.6.tgz",
|
||||||
|
"integrity": "sha512-wA9XS475ZmGNlEnYYLPReSfuz/c3VQsEMoU43mi6OnKMCdbnFXd4/Yg7J0lBv8jkPolacMpOrWEaoYxuE1+hoQ=="
|
||||||
|
},
|
||||||
"source-map": {
|
"source-map": {
|
||||||
"version": "0.6.1",
|
"version": "0.6.1",
|
||||||
"resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz",
|
"resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz",
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
"article-parser": "^4.1.1",
|
"article-parser": "^4.1.1",
|
||||||
"node-downloader-helper": "^1.0.11",
|
"node-downloader-helper": "^1.0.11",
|
||||||
"node-pandoc-promise": "0.0.6",
|
"node-pandoc-promise": "0.0.6",
|
||||||
|
"slugify": "^1.3.6",
|
||||||
"tempfile": "^3.0.0",
|
"tempfile": "^3.0.0",
|
||||||
"yargs": "^15.1.0"
|
"yargs": "^15.1.0"
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue