feat: 获取中山网文章全文预览 (#6029)
This commit is contained in:
parent
0e002343ce
commit
81877beca3
|
|
@ -1,18 +1,32 @@
|
|||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
ctx.params.cateid = ctx.params.cateid || '35';
|
||||
|
||||
const response = await got.get(`http://www.zsnews.cn/api/mobile/getlist.html?cateid=${ctx.params.cateid}`);
|
||||
|
||||
const out = await Promise.all(
|
||||
response.data.map(
|
||||
async (item) =>
|
||||
await ctx.cache.tryGet(item.url, async () => {
|
||||
try {
|
||||
const res = await got.get(item.url);
|
||||
const $ = cheerio.load(res.data);
|
||||
item.description = $('.article-content').html();
|
||||
item.pubDate = new Date($('.article-meta span').first().text().slice(5)).toUTCString();
|
||||
item.link = item.url;
|
||||
return item;
|
||||
} catch (err) {
|
||||
return Promise.resolve('');
|
||||
}
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: '中山新闻',
|
||||
link: 'https://www.zsnews.cn/',
|
||||
item: response.data.map((item) => ({
|
||||
guid: item.id,
|
||||
title: item.title,
|
||||
description: item.title,
|
||||
link: item.url,
|
||||
})),
|
||||
item: out,
|
||||
};
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue