generated from ztimson/template
Create search index cache and return more meta
This commit is contained in:
@@ -5,12 +5,13 @@ export const CATALOG_URL = 'https://library.kiwix.org/catalog/v2/entries';
|
||||
|
||||
const PAGE_SIZE = 100;
|
||||
|
||||
/** Parses `<entry>` blocks out of a Kiwix catalog OPDS XML response. */
|
||||
function parseEntries(xml) {
|
||||
function parseEntries(xml, baseUrl = 'https://library.kiwix.org') {
|
||||
const blocks = xml.match(/<entry>[\s\S]*?<\/entry>/g) || [];
|
||||
return blocks.map(b => {
|
||||
const grab = re => (b.match(re) || [])[1] || '';
|
||||
const linkMatch = b.match(/<link[^>]*type=["']application\/x-zim[^"']*["'][^>]*href=["']([^"']+)["']/);
|
||||
const iconMatch = b.match(/<link[^>]*rel=["']http:\/\/opds-spec\.org\/image\/thumbnail["'][^>]*href=["']([^"']+)["']/)
|
||||
|| b.match(/<link[^>]*type=["']image\/[^"']*["'][^>]*href=["']([^"']+)["']/);
|
||||
let tags = grab(/<tags>([^<]*)<\/tags>/);
|
||||
if(tags) tags = tags.split(';');
|
||||
return {
|
||||
@@ -28,6 +29,7 @@ function parseEntries(xml) {
|
||||
articleCount: Number(grab(/<articleCount>([^<]*)<\/articleCount>/)) || 0,
|
||||
sizeMb: linkMatch ? (Number((b.match(/length=["'](\d+)["']/) || [])[1] || 0) / 1024 / 1024).toFixed(1) : '?',
|
||||
href: linkMatch ? linkMatch[1] : null,
|
||||
icon: iconMatch ? new URL(iconMatch[1], baseUrl).href : null,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user