fix(route/nature): some links in nature siteindex cant access

This commit is contained in:
pseudoyu
2024-10-29 22:52:58 +07:00
parent 528569c567
commit 74f254df09
+25 -11
View File
@@ -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;
})
)
);