fix(route)(wechat/ershicimi): outdated URL (#9494)
* fix(route)(wechat/ershicimi): outdated URL Signed-off-by: Rongrong <15956627+Rongronggg9@users.noreply.github.com> * fix: pubDate
This commit is contained in:
parent
c49b558e3e
commit
eb9026e470
|
|
@ -1,38 +1,30 @@
|
|||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
const { finishArticleItem } = require('@/utils/wechat-mp');
|
||||
const { parseDate } = require('@/utils/parse-date');
|
||||
const timezone = require('@/utils/timezone');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const { id } = ctx.params;
|
||||
const url = `https://www.ershicimi.com/a/${id}`;
|
||||
const rootUrl = 'https://www.cimidata.com';
|
||||
|
||||
const url = `${rootUrl}/a/${id}`;
|
||||
const response = await got(url);
|
||||
const $ = cheerio.load(response.data);
|
||||
const list = $('.weui_media_box')
|
||||
const items = $('.weui_media_box')
|
||||
.map((_, ele) => {
|
||||
const $item = cheerio.load(ele);
|
||||
const link = $item('.weui_media_title a').attr('href');
|
||||
return {
|
||||
title: $item('.weui_media_title a').text(),
|
||||
description: $item('.weui_media_desc').text(),
|
||||
link: `https://www.ershicimi.com${$item('.weui_media_title a').attr('href')}`,
|
||||
pubDate: new Date($item('.weui_media_extra_info').attr('title')).toUTCString(),
|
||||
link,
|
||||
pubDate: timezone(parseDate($item('.weui_media_extra_info').attr('title')), +8),
|
||||
};
|
||||
})
|
||||
.get();
|
||||
|
||||
const items = await Promise.all(
|
||||
list.map((item) =>
|
||||
ctx.cache.tryGet(item.link, async () => {
|
||||
const detailRepsonse = await got({
|
||||
method: 'get',
|
||||
url: item.link,
|
||||
});
|
||||
const content = cheerio.load(detailRepsonse.data);
|
||||
|
||||
item.description = content('.article-content').html() ? content('.article-content').html() : item.description;
|
||||
|
||||
return item;
|
||||
})
|
||||
)
|
||||
);
|
||||
await Promise.all(items.map(async (item) => await finishArticleItem(ctx, item)));
|
||||
|
||||
ctx.state.data = {
|
||||
title: `微信公众号 - ${$('span.name').text()}`,
|
||||
|
|
|
|||
Loading…
Reference in New Issue