diff --git a/abogen/web/static/find_books.js b/abogen/web/static/find_books.js index 7e95c81..9903535 100644 --- a/abogen/web/static/find_books.js +++ b/abogen/web/static/find_books.js @@ -53,6 +53,55 @@ if (modal && browser) { return authors.filter((author) => !!author).join(', '); }; + const formatSeriesIndex = (position) => { + if (position === null || position === undefined) { + return ''; + } + const numeric = Number(position); + if (Number.isFinite(numeric)) { + if (Math.abs(numeric - Math.round(numeric)) < 0.01) { + return String(Math.round(numeric)); + } + return numeric.toLocaleString(undefined, { + minimumFractionDigits: 1, + maximumFractionDigits: 2, + }); + } + if (typeof position === 'string') { + const trimmed = position.trim(); + if (trimmed) { + return trimmed; + } + } + return ''; + }; + + const formatSeriesLabel = (entry) => { + if (!entry) { + return ''; + } + const rawSeries = typeof entry.series === 'string' ? entry.series.trim() : ''; + const rawIndex = + entry.series_index ?? + entry.seriesIndex ?? + entry.series_position ?? + entry.seriesPosition ?? + entry.book_number ?? + entry.bookNumber ?? + null; + const indexLabel = formatSeriesIndex(rawIndex); + if (rawSeries && indexLabel) { + return `${rawSeries} ยท Book ${indexLabel}`; + } + if (rawSeries) { + return rawSeries; + } + if (indexLabel) { + return `Book ${indexLabel}`; + } + return ''; + }; + const setStatus = (message, level) => { if (!statusEl) { return; @@ -257,6 +306,14 @@ if (modal && browser) { header.appendChild(meta); } + const seriesMetaText = formatSeriesLabel(entry); + if (seriesMetaText) { + const seriesMeta = document.createElement('p'); + seriesMeta.className = 'opds-browser__meta'; + seriesMeta.textContent = seriesMetaText; + header.appendChild(seriesMeta); + } + item.appendChild(header); const summarySource = entry.summary || entry?.alternate?.title || entry?.download?.title || '';