Migrated to kiwix-serve
Some checks failed
Publish Library / Build NPM Project (push) Failing after 21s
Publish Library / Tag Version (push) Has been skipped

This commit is contained in:
2026-08-24 20:05:56 -04:00
parent 7d376c90b4
commit db2b334ed6
10 changed files with 545 additions and 723 deletions

View File

@@ -5,7 +5,7 @@ export const CATALOG_URL = 'https://library.kiwix.org';
const PAGE_SIZE = 100;
function parseEntries(xml, catalog = CATALOG_URL) {
export function parseEntries(xml, catalog = CATALOG_URL) {
const blocks = xml.match(/<entry>[\s\S]*?<\/entry>/g) || [];
return blocks.map(b => {
const grab = re => (b.match(re) || [])[1] || '';
@@ -29,7 +29,7 @@ function parseEntries(xml, catalog = CATALOG_URL) {
publisher: grab(/<publisher>\s*<name>([^<]*)<\/name>\s*<\/publisher>/m),
articleCount: Number(grab(/<articleCount>([^<]*)<\/articleCount>/)) || 0,
sizeMb: linkMatch ? +(Number((b.match(/length=["'](\d+)["']/) || [])[1] || 0) / 1024 / 1024).toFixed(1) : '?',
download: linkMatch ? linkMatch[1] : null,
href: linkMatch ? linkMatch[1] : null,
icon: iconMatch ? new URL(iconMatch[1], catalog).href : null,
viewer: name ? new URL(`viewer#${name}`, catalog).href : null,
};
@@ -56,7 +56,7 @@ export async function zimCatalog(terms, opts = {lang: 'eng', count: 20, url: CAT
opts = Object.assign({lang: 'eng', count: 20, url: CATALOG_URL}, opts)
const termList = [...String(terms).split(',')].filter(Boolean).map(t => t.trim().toLowerCase());
const results = await Promise.allSettled(termList.map(t => fetchEntries(t, opts.lang, opts.url)));
const byName = new Map(); // name -> {entry, hitTerms:Set}
const byName = new Map();
results.forEach((r, i) => {
if (r.status !== 'fulfilled') return;
const term = termList[i];