Fixing ISBN and adding Release date.

This commit is contained in:
Vahagn Khachatryan
2019-01-25 22:29:03 +00:00
parent de9eb51894
commit e34a2a2cf6
2 changed files with 20 additions and 4 deletions

View File

@@ -85,6 +85,7 @@ class EpubOpf{
<package xmlns="http://www.idpf.org/2007/opf"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:dcterms="http://purl.org/dc/terms/"
xmlns:opf="http://www.idpf.org/2007/opf"
unique-identifier="pub-id"
version="3.0">
<metadata>
@@ -99,10 +100,18 @@ class EpubOpf{
cnt += ` <dc:description>${m.metadata.description}</dc:description>\n`
}
if (m.metadata.isbn){
cnt += ` <dc:identifier id="isbn">${m.metadata.isbn}</dc:identifier>\n`
cnt += ` <dc:identifier id="isbn" opf:scheme="ISBN">${m.metadata.isbn}</dc:identifier>\n`
let onixcode = m.metadata.isbn.length > 10 ? '15' : '02'
cnt += ` <meta refines="#isbn" property="identifier-type" scheme="onix:codelist5">${onixcode}</meta>\n`
}
if (m.metadata.issued){
try {
let d = new Date(m.metadata.issued)
cnt += ` <dc:date>${d.toISOString()}</dc:date>\n`
} catch(e){
console.warn(`Release data is not valid: "${m.metadata.issued}"`)
}
}
if (m.metadata.publisher){
cnt += ` <dc:publisher>${m.metadata.publisher}</dc:publisher>\n`
}
@@ -255,6 +264,7 @@ class EpubMeta{
this.metadata = {
book_id: 'book_id',
isbn: null,
issued: null,
title: 'title',
language: 'en',
author: [],
@@ -293,11 +303,14 @@ class EpubMeta{
this.metadata.language = escape(lang)
}
addDescription(description){
this.metadata.description = escape(html2txt(description))
this.metadata.description = escape(description)
}
addIsbn(isbn){
this.metadata.isbn = escape(isbn)
}
addIssued(issued){
this.metadata.issued = escape(issued)
}
addMetaData(){
}

View File

@@ -194,7 +194,7 @@ class SidebarPage{
$('#book-info').show();
}
renderDone(){
renderDoneWithBook(){
$('#loading').hide();
}
@@ -270,6 +270,9 @@ function fillMetadata(epub, book)
let subject = book.book_info.subjects[i]
epub.meta.addSubject(subject.name)
}
if (book.book_info.issued){
epub.meta.addIssued(book.book_info.issued)
}
// # The metadata element or deprecated dc-metadata element contains
// # at least one identifier element, at least one title element,
@@ -384,7 +387,7 @@ function onDownloadBookClicked(){
return browser.downloads.download({ "filename" : filename, url : url})
})
.then(() =>{
page.renderDone();
page.renderDoneWithBook();
})
}, onError);