Files
RSSHub/lib/v2/sicau/dky.js
T
Ethan ShenandTonyRL 0fabd6af38 feat(route): add 四川农业大学研究生院 & 动物科技学院 (#7321)
* feat(route): add 四川农业大学研究生院 & 动物科技学院

* fix typo

* refactor: migrate to v2

Co-authored-by: TonyRL <TonyRL@users.noreply.github.com>
2022-02-20 22:43:02 +08:00

54 lines
1.4 KiB
JavaScript

const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
const timezone = require('@/utils/timezone');
module.exports = async (ctx) => {
const category = ctx.params.category ?? 'tzgg';
const rootUrl = 'https://dky.sicau.edu.cn';
const currentUrl = `${rootUrl}/${category}.htm`;
const response = await got({
method: 'get',
url: currentUrl,
});
const $ = cheerio.load(response.data);
const list = $('a.tit')
.slice(0, 10)
.map((_, item) => {
item = $(item);
return {
title: item.text(),
link: `${rootUrl}/${item.attr('href')}`,
pubDate: timezone(parseDate(item.prev().text(), 'YYYY-MM-DD'), +8),
};
})
.get();
const items = await Promise.all(
list.map(
async (item) =>
await ctx.cache.tryGet(item.link, async () => {
const detailResponse = await got({
method: 'get',
url: item.link,
});
const content = cheerio.load(detailResponse.data);
item.description = content('.v_news_content').html();
return item;
})
)
);
ctx.state.data = {
title: $('title').text(),
link: currentUrl,
item: items,
};
};