Files
RSSHub/lib/routes/chinafactcheck/index.ts
T
Tony d585a87daf fix: allow multiple radar rules per route (#14800)
* fix: allow multiple radar rules per route

* fix: github folder

* feat: add namespace to radar target

* docs: fix types url
2024-03-16 03:28:44 +08:00

54 lines
1.3 KiB
TypeScript

import { Route } from '@/types';
import cache from '@/utils/cache';
import utils from './utils';
import { load } from 'cheerio';
import got from '@/utils/got';
export const route: Route = {
path: '/',
radar: [
{
source: ['chinafactcheck.com/'],
target: '',
},
],
name: 'Unknown',
maintainers: ['kdanfly'],
handler,
url: 'chinafactcheck.com/',
};
async function handler() {
const response = await got(utils.siteLink, {
headers: {
'user-agent': utils.trueUA,
},
});
const $ = load(response.data);
const articlesLink = $('.post-info-box .post-thumb a')
.toArray()
.map((item) => ({ link: $(item).attr('href') }));
const articles = await Promise.all(
articlesLink.map((item) =>
cache.tryGet(item.link, async () => {
const { title, author, pubDate, description, category } = await utils.getArticleDetail(item.link);
item.title = title;
item.author = author;
item.pubDate = pubDate;
item.description = description;
item.category = category;
return item;
})
)
);
return {
title: $('head title').text(),
link: utils.siteLink,
item: articles,
};
}