fix(route): 更换财新最新文章获取方式 (#13023)
* 更换财新最新文章获取方式。 * Update latest.js * Update latest.js * Update latest.js
This commit is contained in:
parent
06f43cb664
commit
0d0ec741c1
|
|
@ -1,18 +1,17 @@
|
|||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
const { parseDate } = require('@/utils/parse-date');
|
||||
const timezone = require('@/utils/timezone');
|
||||
const { art } = require('@/utils/render');
|
||||
const path = require('path');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const li_r = await got('https://www.caixin.com/search/scroll/0.jsp');
|
||||
const {data} = await got('https://gateway.caixin.com/api/dataplatform/scroll/index').json();
|
||||
|
||||
const $ = cheerio.load(li_r.data);
|
||||
const list = $('div.news_content dl dd')
|
||||
.toArray()
|
||||
.map((dd) => ({
|
||||
link: $(dd).find('a').first().attr('href').replace('http://', 'https://'),
|
||||
const list = data
|
||||
.articleList.map((e) => ({
|
||||
title: e.title,
|
||||
link: e.url,
|
||||
pubDate: e.time,
|
||||
category: e.channelObject.name
|
||||
}))
|
||||
.filter((item) => !item.link.startsWith('https://fm.caixin.com/') && !item.link.startsWith('https://video.caixin.com/') && !item.link.startsWith('https://datanews.caixin.com/')); // content filter
|
||||
|
||||
|
|
@ -21,8 +20,6 @@ module.exports = async (ctx) => {
|
|||
ctx.cache.tryGet(`caixin:latest:${item.link}`, async () => {
|
||||
const entry_r = await got(item.link);
|
||||
const $ = cheerio.load(entry_r.data);
|
||||
// title
|
||||
const h1 = $('#conTit h1').text();
|
||||
|
||||
// desc
|
||||
const desc = art(path.join(__dirname, 'templates/article.art'), {
|
||||
|
|
@ -30,9 +27,7 @@ module.exports = async (ctx) => {
|
|||
$,
|
||||
});
|
||||
|
||||
item.title = h1;
|
||||
item.description = desc;
|
||||
item.pubDate = timezone(parseDate($('#pubtime_baidu').text()), +8);
|
||||
// prevent cache coliision with /caixin/article and /caixin/:column/:category
|
||||
// since those have podcasts
|
||||
item.guid = `caixin:latest:${item.link}`;
|
||||
|
|
|
|||
Loading…
Reference in New Issue