OPDS: improve metadata

This commit is contained in:
John Factotum
2024-10-06 10:16:46 +08:00
parent e384aaf6dd
commit 2e8b4fab0d
+13 -8
View File
@@ -125,6 +125,15 @@ const getLink = link => {
return obj return obj
} }
const getPerson = person => {
const NS = person.namespaceURI
const uri = person.getElementsByTagNameNS(NS, 'uri')[0]?.textContent
return {
name: person.getElementsByTagNameNS(NS, 'name')[0]?.textContent ?? '',
links: uri ? [{ href: uri }] : [],
}
}
export const getPublication = entry => { export const getPublication = entry => {
const filter = filterNS(useNS(entry.ownerDocument, NS.ATOM)) const filter = filterNS(useNS(entry.ownerDocument, NS.ATOM))
const children = Array.from(entry.children) const children = Array.from(entry.children)
@@ -139,14 +148,8 @@ export const getPublication = entry => {
return { return {
metadata: { metadata: {
title: children.find(filter('title'))?.textContent ?? '', title: children.find(filter('title'))?.textContent ?? '',
author: children.filter(filter('author')).map(person => { author: children.filter(filter('author')).map(getPerson),
const NS = person.namespaceURI contributor: children.filter(filter('contributor')).map(getPerson),
const uri = person.getElementsByTagNameNS(NS, 'uri')[0]?.textContent
return {
name: person.getElementsByTagNameNS(NS, 'name')[0]?.textContent ?? '',
links: uri ? [{ href: uri }] : [],
}
}),
publisher: children.find(filterDC('publisher'))?.textContent, publisher: children.find(filterDC('publisher'))?.textContent,
published: (children.find(filterDCTERMS('issued')) published: (children.find(filterDCTERMS('issued'))
?? children.find(filterDC('date')))?.textContent, ?? children.find(filterDC('date')))?.textContent,
@@ -155,7 +158,9 @@ export const getPublication = entry => {
subject: children.filter(filter('category')).map(category => ({ subject: children.filter(filter('category')).map(category => ({
name: category.getAttribute('label'), name: category.getAttribute('label'),
code: category.getAttribute('term'), code: category.getAttribute('term'),
scheme: category.getAttribute('scheme'),
})), })),
rights: children.find(filter('rights'))?.textContent ?? '',
[SYMBOL.CONTENT]: getContent(children.find(filter('content')) [SYMBOL.CONTENT]: getContent(children.find(filter('content'))
?? children.find(filter('summary'))), ?? children.find(filter('summary'))),
}, },