RSSHub/lib/routes/aisixiang/utils.ts

40 lines
1.5 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import got from '@/utils/got';
import { load } from 'cheerio';
import timezone from '@/utils/timezone';
import { parseDate } from '@/utils/parse-date';
const ossUrl = 'https://oss.aisixiang.com';
const rootUrl = 'https://www.aisixiang.com';
const ProcessFeed = (limit, tryGet, items) =>
Promise.all(
items.slice(0, limit).map((item) =>
tryGet(item.link, async () => {
const { data: detailResponse } = await got(item.link);
const content = load(detailResponse);
const commentMatches = content('h3.comment-header')
.text()
.match(/评论(\d+/);
item.title = content('h3').first().text().split('').pop();
item.description = content('div.article-content').html();
item.author = content('div.about strong').first().text();
item.category = content('u')
.first()
.parent()
.find('u')
.toArray()
.map((c) => content(c).text());
item.pubDate = timezone(parseDate(content('div.info').text().split('时间:').pop()), +8);
item.upvotes = content('span.like-num').text() ? Number.parseInt(content('span.like-num').text(), 10) : 0;
item.comments = commentMatches ? Number.parseInt(commentMatches[1], 10) : 0;
return item;
})
)
);
export { rootUrl, ossUrl, ProcessFeed };