generated from ztimson/template
Migrated to kiwix-serve
This commit is contained in:
@@ -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];
|
||||
|
||||
Reference in New Issue
Block a user