mirror of
https://github.com/DIYgod/RSSHub.git
synced 2026-08-31 01:01:11 +08:00
feat(route/yicai): Add route for carousel part on front page (#16433)
* feat(route/yicai): Add route for carousel part on front page * . * . * . * . * . * ...ESLint...
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
import { Route } from '@/types';
|
||||
import cache from '@/utils/cache';
|
||||
import { rootUrl, fetchFullArticles } from './utils';
|
||||
import ofetch from '@/utils/ofetch';
|
||||
import { load } from 'cheerio';
|
||||
|
||||
export const route: Route = {
|
||||
path: '/carousel',
|
||||
categories: ['traditional-media'],
|
||||
example: '/yicai/carousel',
|
||||
parameters: {},
|
||||
features: {
|
||||
requireConfig: false,
|
||||
requirePuppeteer: false,
|
||||
antiCrawler: false,
|
||||
supportBT: false,
|
||||
supportPodcast: false,
|
||||
supportScihub: false,
|
||||
},
|
||||
radar: [
|
||||
{
|
||||
source: ['yicai.com/'],
|
||||
},
|
||||
],
|
||||
name: '轮播',
|
||||
maintainers: ['nczitzk'],
|
||||
handler,
|
||||
url: 'yicai.com/',
|
||||
};
|
||||
|
||||
async function handler() {
|
||||
const res = await ofetch(rootUrl);
|
||||
const $ = load(res);
|
||||
const items = await Promise.all(
|
||||
fetchFullArticles(
|
||||
$('#breaknews a')
|
||||
.toArray()
|
||||
.map((e) => ({ link: new URL($(e).attr('href'), rootUrl).href, title: $(e).text() })),
|
||||
cache.tryGet
|
||||
)
|
||||
);
|
||||
|
||||
return {
|
||||
title: '第一财经 - 轮播',
|
||||
link: rootUrl,
|
||||
item: items,
|
||||
};
|
||||
}
|
||||
+26
-20
@@ -35,25 +35,31 @@ const ProcessItems = async (apiUrl, tryGet) => {
|
||||
}),
|
||||
}));
|
||||
|
||||
return Promise.all(
|
||||
items.map((item) =>
|
||||
tryGet(item.link, async () => {
|
||||
const detailResponse = await got({
|
||||
method: 'get',
|
||||
url: item.link,
|
||||
});
|
||||
|
||||
const content = load(detailResponse.data);
|
||||
|
||||
content('h1').remove();
|
||||
content('.u-btn6, .m-smallshare, .topic-hot').remove();
|
||||
|
||||
item.description += content('.multiText, #multi-text, .txt').html() ?? '';
|
||||
|
||||
return item;
|
||||
})
|
||||
)
|
||||
);
|
||||
return Promise.all(fetchFullArticles(items, tryGet));
|
||||
};
|
||||
function fetchFullArticles(items, tryGet) {
|
||||
return items.map((item) =>
|
||||
tryGet(item.link, async () => {
|
||||
const detailResponse = await got({
|
||||
method: 'get',
|
||||
url: item.link,
|
||||
});
|
||||
|
||||
export { rootUrl, ProcessItems };
|
||||
const content = load(detailResponse.data);
|
||||
|
||||
if (!item.pubDate) {
|
||||
const dataScript = content("script[src='/js/alert.min.js']").next().text() || content('title').next().text();
|
||||
const pb = new Map(JSON.parse(dataScript.match(/_pb = (\[.*?]);/)[1].replaceAll("'", '"')));
|
||||
item.pubDate = parseDate(`${pb.get('actime')}:00`);
|
||||
}
|
||||
|
||||
content('h1').remove();
|
||||
content('.u-btn6, .m-smallshare, .topic-hot').remove();
|
||||
|
||||
item.description = (item.description ?? '') + (content('.multiText, #multi-text, .txt').html() ?? '');
|
||||
|
||||
return item;
|
||||
})
|
||||
);
|
||||
}
|
||||
export { rootUrl, ProcessItems, fetchFullArticles };
|
||||
|
||||
Reference in New Issue
Block a user