EPUB: redo metadata parsing

- Support the `prefix` attribute (for the `property` attr on `<meta>`)
- Localized titles, names (including `sortAs`)
- `belongsTo`, including `calibre:series`
- `altIdentifier`, converted to URN where possible
- Remove `producer`. It's now `contributor` with `role: 'bkp'`.

NOTE: this is a breaking change if you assumed that `title` will always
be a string, `author` will always be an array, etc.
This commit is contained in:
John Factotum
2024-09-18 11:28:08 +08:00
parent e6937eed15
commit 541bc07b6f
4 changed files with 228 additions and 152 deletions
+17 -7
View File
@@ -151,6 +151,21 @@ const $ = document.querySelector.bind(document)
const locales = 'en'
const percentFormat = new Intl.NumberFormat(locales, { style: 'percent' })
const listFormat = new Intl.ListFormat(locales, { style: 'short', type: 'conjunction' })
const formatLanguageMap = x => {
if (!x) return ''
if (typeof x === 'string') return x
const keys = Object.keys(x)
return x[keys[0]]
}
const formatOneContributor = contributor => typeof contributor === 'string'
? contributor : formatLanguageMap(contributor?.name)
const formatContributor = contributor => Array.isArray(contributor)
? listFormat.format(contributor.map(formatOneContributor))
: formatOneContributor(contributor)
class Reader {
#tocView
@@ -219,15 +234,10 @@ class Reader {
document.addEventListener('keydown', this.#handleKeydown.bind(this))
const title = book.metadata?.title ?? 'Untitled Book'
const title = formatLanguageMap(book.metadata?.title) || 'Untitled Book'
document.title = title
$('#side-bar-title').innerText = title
const author = book.metadata?.author
$('#side-bar-author').innerText = typeof author === 'string' ? author
: author
?.map(author => typeof author === 'string' ? author : author.name)
?.join(', ')
?? ''
$('#side-bar-author').innerText = formatContributor(book.metadata?.author)
Promise.resolve(book.getCover?.())?.then(blob =>
blob ? $('#side-bar-cover').src = URL.createObjectURL(blob) : null)