Skip to content

Commit

Permalink
fix(route): 更换财新最新文章获取方式 (DIYgod#13023)
Browse files Browse the repository at this point in the history
* 更换财新最新文章获取方式。

* Update latest.js

* Update latest.js

* Update latest.js
  • Loading branch information
dzx-dzx authored Aug 15, 2023
1 parent 06f43cb commit 0d0ec74
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions lib/v2/caixin/latest.js
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -21,18 +20,14 @@ 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'), {
item,
$,
});

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}`;
Expand Down

0 comments on commit 0d0ec74

Please sign in to comment.