Skip to content

Commit

Permalink
fix(route/nature): some links in nature siteindex cant access
Browse files Browse the repository at this point in the history
  • Loading branch information
pseudoyu committed Oct 29, 2024
1 parent 528569c commit 74f254d
Showing 1 changed file with 25 additions and 11 deletions.
36 changes: 25 additions & 11 deletions lib/routes/nature/siteindex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const route: Route = {
supportScihub: false,
},
name: 'Journal List',
maintainers: ['TonyRL'],
maintainers: ['TonyRL', 'pseudoyu'],
handler,
};

Expand All @@ -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;
})
)
);
Expand Down

0 comments on commit 74f254d

Please sign in to comment.