v1.0.0
This commit is contained in:
parent
3f73dd4c31
commit
e4849f728b
|
@ -0,0 +1,7 @@
|
|||
Copyright 2019 Abhay Rana
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@ -0,0 +1,40 @@
|
|||
# url-to-epub
|
||||
|
||||
A simple script that generates an EPUB from a single URL, taking care for the following:
|
||||
|
||||
1. Cover Image
|
||||
2. Readability
|
||||
3. Standard-compliance metadata (and Author information)
|
||||
|
||||
## Installation
|
||||
|
||||
You will need `pandoc` and `npm` installed. To install this script globally:
|
||||
|
||||
npm install --global url-to-epub
|
||||
|
||||
Please make sure that the global node_modules/bin directory is added to your PATH.
|
||||
You can check that directory by running `npm bin --global`.
|
||||
|
||||
## Usage
|
||||
|
||||
```
|
||||
url-to-epub <url>
|
||||
|
||||
Generate EPUB file from URL
|
||||
|
||||
Positionals:
|
||||
url The URL to download [string] [required]
|
||||
|
||||
Options:
|
||||
--version Show version number [boolean]
|
||||
-h Show help [boolean]
|
||||
--output, -o Output file to save EPUB [string] [default: "url-to-epub.epub"]
|
||||
|
||||
Examples:
|
||||
url-to-epub -o articulated-restraint.epub
|
||||
"https://www.tor.com/2019/02/06/articulated-restraint-mary-robinette-kowal/"
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
Licensed under the [MIT License](https://nemo.mit-license.org/). See LICENSE file for details.
|
|
@ -0,0 +1,9 @@
|
|||
General ideas for improvement of the script:
|
||||
|
||||
1. Support multiple authors
|
||||
2. Support no cover image
|
||||
3. Support generic generated cover images
|
||||
4. Remove pandoc dependency
|
||||
5. Optionally support <https://github.com/mozilla/readability> instead of article-parser. Mozilla's engine is much better.
|
||||
6. Add more EPUB metadata tag support
|
||||
7. Pick up the language automatically
|
|
@ -13,11 +13,12 @@ const getArticle = async url => {
|
|||
}
|
||||
};
|
||||
|
||||
module.exports = (url, epubPath) => {
|
||||
module.exports = (url, epubPath, language="en-US") => {
|
||||
getArticle(url).then(res => {
|
||||
let xml = `<dc:title id="epub-title-1">${res.title}</dc:title>
|
||||
<dc:date>${res.published}</dc:date>
|
||||
<dc:language>en-US</dc:language>
|
||||
<dc:language>${language}</dc:language>
|
||||
<dc:identifier>${url}</dc:identifier>
|
||||
<dc:creator id="epub-creator-1" opf:role="aut">${res.author}</dc:creator>`;
|
||||
|
||||
let html = tempFile(".html");
|
||||
|
|
283
index.js
283
index.js
|
@ -5,22 +5,267 @@ const generateEPUB = require("./generate");
|
|||
require("yargs") // eslint-disable-line
|
||||
.usage("$0 --output [output] <url>")
|
||||
.help("h")
|
||||
.command("$0 <url>", "Generate EPUB file from URL", yargs => {
|
||||
yargs
|
||||
.positional("url", {
|
||||
describe: "The URL to download",
|
||||
type: "string"
|
||||
})
|
||||
.option("output", {
|
||||
alias: "o",
|
||||
type: "string",
|
||||
default: "url-to-epub.epub",
|
||||
description: "Output file to save EPUB"
|
||||
})
|
||||
.example(
|
||||
'$0 -o articulated-restraint.epub "https://www.tor.com/2019/02/06/articulated-restraint-mary-robinette-kowal/"'
|
||||
)
|
||||
.demandOption(["url"]);
|
||||
}, (argv) => {
|
||||
generateEPUB(argv.url, argv.output)
|
||||
}).argv;
|
||||
.command(
|
||||
"$0 <url>",
|
||||
"Generate EPUB file from URL",
|
||||
yargs => {
|
||||
yargs
|
||||
.positional("url", {
|
||||
describe: "The URL to download",
|
||||
type: "string"
|
||||
})
|
||||
.option("output", {
|
||||
alias: "o",
|
||||
type: "string",
|
||||
default: "url-to-epub.epub",
|
||||
description: "Output file to save EPUB"
|
||||
})
|
||||
.option("language", {
|
||||
alias: "l",
|
||||
type: "string",
|
||||
default: "en-US",
|
||||
description: "A valid language tag",
|
||||
choices: [
|
||||
"af",
|
||||
"af-ZA",
|
||||
"ar",
|
||||
"ar-AE",
|
||||
"ar-BH",
|
||||
"ar-DZ",
|
||||
"ar-EG",
|
||||
"ar-IQ",
|
||||
"ar-JO",
|
||||
"ar-KW",
|
||||
"ar-LB",
|
||||
"ar-LY",
|
||||
"ar-MA",
|
||||
"ar-OM",
|
||||
"ar-QA",
|
||||
"ar-SA",
|
||||
"ar-SY",
|
||||
"ar-TN",
|
||||
"ar-YE",
|
||||
"az",
|
||||
"az-AZ",
|
||||
"az-Cyrl-AZ",
|
||||
"be",
|
||||
"be-BY",
|
||||
"bg",
|
||||
"bg-BG",
|
||||
"bs-BA",
|
||||
"ca",
|
||||
"ca-ES",
|
||||
"cs",
|
||||
"cs-CZ",
|
||||
"cy",
|
||||
"cy-GB",
|
||||
"da",
|
||||
"da-DK",
|
||||
"de",
|
||||
"de-AT",
|
||||
"de-CH",
|
||||
"de-DE",
|
||||
"de-LI",
|
||||
"de-LU",
|
||||
"dv",
|
||||
"dv-MV",
|
||||
"el",
|
||||
"el-GR",
|
||||
"en",
|
||||
"en-AU",
|
||||
"en-BZ",
|
||||
"en-CA",
|
||||
"en-CB",
|
||||
"en-GB",
|
||||
"en-IE",
|
||||
"en-JM",
|
||||
"en-NZ",
|
||||
"en-PH",
|
||||
"en-TT",
|
||||
"en-US",
|
||||
"en-ZA",
|
||||
"en-ZW",
|
||||
"eo",
|
||||
"es",
|
||||
"es-AR",
|
||||
"es-BO",
|
||||
"es-CL",
|
||||
"es-CO",
|
||||
"es-CR",
|
||||
"es-DO",
|
||||
"es-EC",
|
||||
"es-ES",
|
||||
"es-GT",
|
||||
"es-HN",
|
||||
"es-MX",
|
||||
"es-NI",
|
||||
"es-PA",
|
||||
"es-PE",
|
||||
"es-PR",
|
||||
"es-PY",
|
||||
"es-SV",
|
||||
"es-UY",
|
||||
"es-VE",
|
||||
"et",
|
||||
"et-EE",
|
||||
"eu",
|
||||
"eu-ES",
|
||||
"fa",
|
||||
"fa-IR",
|
||||
"fi",
|
||||
"fi-FI",
|
||||
"fo",
|
||||
"fo-FO",
|
||||
"fr",
|
||||
"fr-BE",
|
||||
"fr-CA",
|
||||
"fr-CH",
|
||||
"fr-FR",
|
||||
"fr-LU",
|
||||
"fr-MC",
|
||||
"gl",
|
||||
"gl-ES",
|
||||
"gu",
|
||||
"gu-IN",
|
||||
"he",
|
||||
"he-IL",
|
||||
"hi",
|
||||
"hi-IN",
|
||||
"hr",
|
||||
"hr-BA",
|
||||
"hr-HR",
|
||||
"hu",
|
||||
"hu-HU",
|
||||
"hy",
|
||||
"hy-AM",
|
||||
"id",
|
||||
"id-ID",
|
||||
"is",
|
||||
"is-IS",
|
||||
"it",
|
||||
"it-CH",
|
||||
"it-IT",
|
||||
"ja",
|
||||
"ja-JP",
|
||||
"ka",
|
||||
"ka-GE",
|
||||
"kk",
|
||||
"kk-KZ",
|
||||
"kn",
|
||||
"kn-IN",
|
||||
"ko",
|
||||
"ko-KR",
|
||||
"kok",
|
||||
"kok-IN",
|
||||
"ky",
|
||||
"ky-KG",
|
||||
"lt",
|
||||
"lt-LT",
|
||||
"lv",
|
||||
"lv-LV",
|
||||
"mi",
|
||||
"mi-NZ",
|
||||
"mk",
|
||||
"mk-MK",
|
||||
"mn",
|
||||
"mn-MN",
|
||||
"mr",
|
||||
"mr-IN",
|
||||
"ms",
|
||||
"ms-BN",
|
||||
"ms-MY",
|
||||
"mt",
|
||||
"mt-MT",
|
||||
"nb",
|
||||
"nb-NO",
|
||||
"nl",
|
||||
"nl-BE",
|
||||
"nl-NL",
|
||||
"nn-NO",
|
||||
"ns",
|
||||
"ns-ZA",
|
||||
"pa",
|
||||
"pa-IN",
|
||||
"pl",
|
||||
"pl-PL",
|
||||
"ps",
|
||||
"ps-AR",
|
||||
"pt",
|
||||
"pt-BR",
|
||||
"pt-PT",
|
||||
"qu",
|
||||
"qu-BO",
|
||||
"qu-EC",
|
||||
"qu-PE",
|
||||
"ro",
|
||||
"ro-RO",
|
||||
"ru",
|
||||
"ru-RU",
|
||||
"sa",
|
||||
"sa-IN",
|
||||
"se",
|
||||
"se-FI",
|
||||
"se-NO",
|
||||
"se-SE",
|
||||
"sk",
|
||||
"sk-SK",
|
||||
"sl",
|
||||
"sl-SI",
|
||||
"sq",
|
||||
"sq-AL",
|
||||
"sr-BA",
|
||||
"sr-Cyrl-BA",
|
||||
"sr-SP",
|
||||
"sr-Cyrl-SP",
|
||||
"sv",
|
||||
"sv-FI",
|
||||
"sv-SE",
|
||||
"sw",
|
||||
"sw-KE",
|
||||
"syr",
|
||||
"syr-SY",
|
||||
"ta",
|
||||
"ta-IN",
|
||||
"te",
|
||||
"te-IN",
|
||||
"th",
|
||||
"th-TH",
|
||||
"tl",
|
||||
"tl-PH",
|
||||
"tn",
|
||||
"tn-ZA",
|
||||
"tr",
|
||||
"tr-TR",
|
||||
"tt",
|
||||
"tt-RU",
|
||||
"ts",
|
||||
"uk",
|
||||
"uk-UA",
|
||||
"ur",
|
||||
"ur-PK",
|
||||
"uz",
|
||||
"uz-UZ",
|
||||
"uz-Cyrl-UZ",
|
||||
"vi",
|
||||
"vi-VN",
|
||||
"xh",
|
||||
"xh-ZA",
|
||||
"zh",
|
||||
"zh-CN",
|
||||
"zh-HK",
|
||||
"zh-MO",
|
||||
"zh-SG",
|
||||
"zh-TW",
|
||||
"zu",
|
||||
"zu-ZA"
|
||||
]
|
||||
})
|
||||
.example(
|
||||
'$0 -o articulated-restraint.epub "https://www.tor.com/2019/02/06/articulated-restraint-mary-robinette-kowal/"'
|
||||
)
|
||||
.demandOption(["url"]);
|
||||
},
|
||||
argv => {
|
||||
generateEPUB(argv.url, argv.output);
|
||||
}
|
||||
).argv;
|
||||
|
|
Loading…
Reference in New Issue