mirror of
https://github.com/john-okeefe/foliate-js.git
synced 2026-09-09 11:29:14 -04:00
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:
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user