Fixes dc:date element

This commit is contained in:
Nemo 2020-01-28 02:24:33 +05:30
parent 884cdb42eb
commit c654c33f91
4 changed files with 22 additions and 3 deletions

View File

@ -5,6 +5,10 @@ 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.2]
### Fixed
- Fixed `dc:date` element (publication date) in the generated EPUB
## [1.2.1]
### Added

View File

@ -22,8 +22,23 @@ module.exports = (url, epubPath, title, coverURL, language="en-US") => {
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:source>${url}</dc:source>

2
package-lock.json generated
View File

@ -1,6 +1,6 @@
{
"name": "url-to-epub",
"version": "1.2.0",
"version": "1.2.2",
"lockfileVersion": 1,
"requires": true,
"dependencies": {

View File

@ -1,6 +1,6 @@
{
"name": "url-to-epub",
"version": "1.2.1",
"version": "1.2.2",
"description": "A single tool to generate a standards-compliant EPUB from a webpage. Zero config. Requires pandoc",
"main": "index.js",
"bin": {