Files
RSSHub/lib/v2/chaping/banner.js
Fatpandac ea0022cbcf feat(route): add 差评快讯 and refactor to V2 (#9319)
* feat(route): add 差评快讯 and refactor to V2

* fix: parseDate
2022-03-15 02:30:06 +08:00

41 lines
1.2 KiB
JavaScript

const got = require('@/utils/got');
const { parseDate } = require('@/utils/parse-date');
module.exports = async (ctx) => {
const rootUrl = `https://chaping.cn/`;
const response = await got({
method: 'get',
url: rootUrl,
});
const data = JSON.parse(response.data.match(/"bannerList":(.*?),"menu":/)[1]);
const bannerList = data.map((item) => ({
title: item.news_title,
link: `https://chaping.cn/news/${item.news_id}`,
}));
const items = await Promise.all(
bannerList.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const detailResponse = await got({
method: 'get',
url: item.link,
});
const content = JSON.parse(detailResponse.data.match(/"current":(.*?),"optionsList":/)[1]);
item.description = content.content;
item.author = content.article_author.name;
item.pubDate = parseDate(content.time_publish_timestamp * 1000);
return item;
})
)
);
ctx.state.data = {
title: '差评 - 首页图片墙',
link: rootUrl,
item: items,
};
};