From 74f254df094d097e0e1d1d9ccc1b2d4732ca1944 Mon Sep 17 00:00:00 2001 From: pseudoyu Date: Tue, 29 Oct 2024 22:52:58 +0700 Subject: [PATCH] fix(route/nature): some links in nature siteindex cant access --- lib/routes/nature/siteindex.ts | 36 +++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/lib/routes/nature/siteindex.ts b/lib/routes/nature/siteindex.ts index 99ec1d80957bf5..d927800dd87d7e 100644 --- a/lib/routes/nature/siteindex.ts +++ b/lib/routes/nature/siteindex.ts @@ -18,7 +18,7 @@ export const route: Route = { supportScihub: false, }, name: 'Journal List', - maintainers: ['TonyRL'], + maintainers: ['TonyRL', 'pseudoyu'], handler, }; @@ -40,19 +40,33 @@ async function handler(ctx) { items = await Promise.all( items.map((item) => cache.tryGet(`nature:siteindex:${item.title}`, async () => { - const response = await got(item.link, { cookieJar }); - const $ = load(response.data); - - delete item.link; try { - item.id = $('.app-latest-issue-row__image img') - .attr('src') - .match(/.*\/journal\/(\d{5})/)[1]; - item.description = item.id; + const response = await got(item.link, { cookieJar }); + const $ = load(response.data); + + const imgSrc = $('.app-latest-issue-row__image img').attr('src'); + if (imgSrc) { + const match = imgSrc.match(/.*\/journal\/(\d{5})/); + if (match) { + const id = match[1]; + return { + title: item.title, + name: item.name, + id, + description: id, + }; + } + } + return { + title: item.title, + name: item.name, + }; } catch { - // + return { + title: item.title, + name: item.name, + }; } - return item; }) ) );