Compare commits
8 Commits
Author | SHA1 | Date |
---|---|---|
Nemo | cdfda9714f | |
Nemo | ed11dff030 | |
Nemo | 014231895c | |
Nemo | 98721bf6ef | |
Nemo | ab0f565a8c | |
Nemo | c654c33f91 | |
Nemo | 884cdb42eb | |
Nemo | a46bb80ac8 |
|
@ -0,0 +1,3 @@
|
|||
ko_fi: captn3m0
|
||||
liberapay: captn3m0
|
||||
github: captn3m0
|
17
CHANGELOG.md
17
CHANGELOG.md
|
@ -5,6 +5,23 @@ All notable changes to this project will be documented in this file.
|
|||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## [1.2.3]
|
||||
### Changed
|
||||
- Dependency updates
|
||||
|
||||
## [1.2.2]
|
||||
### Fixed
|
||||
- Fixed `dc:date` element (publication date) in the generated EPUB
|
||||
|
||||
## [1.2.1]
|
||||
|
||||
### Added
|
||||
- Default filename is now generated
|
||||
- Added publisher and source tags in generate EPUB
|
||||
|
||||
### Fixed
|
||||
- Fixed a bug where the cover image was getting reused
|
||||
|
||||
## [1.2.0]
|
||||
### Added
|
||||
- Docker Image published
|
||||
|
|
2
LICENSE
2
LICENSE
|
@ -1,4 +1,4 @@
|
|||
Copyright 2019 Abhay Rana
|
||||
Copyright 2020 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:
|
||||
|
||||
|
|
29
generate.js
29
generate.js
|
@ -3,6 +3,8 @@ const tempFile = require("tempfile");
|
|||
const nodePandoc = require("node-pandoc-promise");
|
||||
const fs = require("fs");
|
||||
const { DownloaderHelper } = require("node-downloader-helper");
|
||||
const path = require('path');
|
||||
const slugify = require('slugify');
|
||||
|
||||
const getArticle = async url => {
|
||||
try {
|
||||
|
@ -18,11 +20,31 @@ module.exports = (url, epubPath, title, coverURL, language="en-US") => {
|
|||
|
||||
title = title ? title : res.title;
|
||||
|
||||
epubPath = epubPath ? epubPath : slugify(path.basename(url)) + '.epub';
|
||||
|
||||
let date = new Date(Date.parse(res.published));
|
||||
|
||||
|
||||
function pad(number) {
|
||||
if (number < 10) {
|
||||
return '0' + number;
|
||||
}
|
||||
return number;
|
||||
}
|
||||
|
||||
// Using toISOString() trips Pandoc, which leaves an empty dc:date element instead.
|
||||
let epubDate = date.getUTCFullYear() +
|
||||
'-' + pad(date.getUTCMonth() + 1) +
|
||||
'-' + pad(date.getUTCDate());
|
||||
|
||||
let xml = `<dc:title id="epub-title-1">${title}</dc:title>
|
||||
<dc:date>${res.published}</dc:date>
|
||||
<dc:date>${epubDate}</dc:date>
|
||||
<dc:language>${language}</dc:language>
|
||||
<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 metadata = tempFile(".xml");
|
||||
|
@ -32,7 +54,8 @@ module.exports = (url, epubPath, title, coverURL, language="en-US") => {
|
|||
const imageUrl = coverURL ? coverURL : res.image;
|
||||
|
||||
const dl = new DownloaderHelper(imageUrl, "/tmp", {
|
||||
fileName: "epub-to-image.jpg"
|
||||
fileName: "epub-to-image.jpg",
|
||||
override: true
|
||||
});
|
||||
|
||||
dl.start();
|
||||
|
|
2
index.js
2
index.js
|
@ -17,7 +17,7 @@ require("yargs") // eslint-disable-line
|
|||
.option("output", {
|
||||
alias: "o",
|
||||
type: "string",
|
||||
default: "url-to-epub.epub",
|
||||
default: false,
|
||||
description: "Output file to save EPUB"
|
||||
})
|
||||
.option("title", {
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "url-to-epub",
|
||||
"version": "1.2.0",
|
||||
"version": "1.2.4",
|
||||
"description": "A single tool to generate a standards-compliant EPUB from a webpage. Zero config. Requires pandoc",
|
||||
"main": "index.js",
|
||||
"bin": {
|
||||
|
@ -14,10 +14,11 @@
|
|||
"author": "Nemo",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"article-parser": "^4.1.1",
|
||||
"node-downloader-helper": "^1.0.11",
|
||||
"article-parser": "^4.2.1",
|
||||
"node-downloader-helper": "^1.0.13",
|
||||
"node-pandoc-promise": "0.0.6",
|
||||
"slugify": "^1.4.4",
|
||||
"tempfile": "^3.0.0",
|
||||
"yargs": "^15.1.0"
|
||||
"yargs": "^15.4.1"
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue