fix(route): 中国人民大学人事处 (#8620)

This commit is contained in:
Ethan Shen 2022-01-23 00:12:09 +08:00 committed by GitHub
parent b04a5b8ff7
commit dff523d194
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 20 additions and 14 deletions

View File

@ -15,29 +15,35 @@ module.exports = async (ctx) => {
const $ = cheerio.load(response.data);
const list = $('a[title]')
.map((_, item) => {
let items = $('a[title]')
.toArray()
.map((item) => {
item = $(item);
const link = item.attr('href');
return {
title: item.text(),
link: `${rootUrl}/${category}/${item.attr('href')}`,
link: `${rootUrl}${link.indexOf('..') === 0 ? link.replace(/\.\./, '') : `/${category}/${link}`}`,
};
})
.get();
});
const items = await Promise.all(
list.map((item) =>
items = await Promise.all(
items.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const detailResponse = await got({
method: 'get',
url: item.link,
});
try {
const detailResponse = await got({
method: 'get',
url: item.link,
});
const content = cheerio.load(detailResponse.data);
const content = cheerio.load(detailResponse.data);
item.description = content('.neirong').html();
item.pubDate = parseDate(detailResponse.data.match(/日期:(\d{4}-\d{2}-\d{2})/)[1]);
item.description = content('.neirong').html();
item.pubDate = parseDate(detailResponse.data.match(/日期:(\d{4}-\d{2}-\d{2})/)[1]);
} catch (err) {
item.description = 'Not Found';
}
return item;
})