diff --git a/src/lib/opds.client.ts b/src/lib/opds.client.ts index db538c0..e82da71 100644 --- a/src/lib/opds.client.ts +++ b/src/lib/opds.client.ts @@ -111,9 +111,28 @@ function isNavigationLink(link: ParsedFeedLink): boolean { return isNavigationRel(link.rel) || type.includes('kind=navigation') || (type.includes('opds-catalog') && !isAcquisitionRel(link.rel)); } +function isCoverRel(rel?: string): boolean { + if (!rel) return false; + const normalized = rel.toLowerCase(); + return normalized.includes('opds-spec.org/cover') + || normalized.includes('opds-spec.org/image') + || normalized.includes('image/thumbnail') + || normalized === 'thumbnail' + || normalized === 'cover'; +} + +function isImageType(type?: string): boolean { + return !!type && type.toLowerCase().startsWith('image/'); +} + function pickCoverLink(links: ParsedFeedLink[]): string | undefined { - const cover = links.find((link) => link.rel?.includes('image/thumbnail')) - || links.find((link) => link.rel?.includes('image')); + const thumbnail = links.find((link) => { + const rel = (link.rel || '').toLowerCase(); + return rel.includes('thumbnail') && (isCoverRel(link.rel) || isImageType(link.type)); + }); + const cover = thumbnail + || links.find((link) => isCoverRel(link.rel)) + || links.find((link) => isImageType(link.type) && !isAcquisitionRel(link.rel)); return cover?.href; }