Files
RSSHub/lib/routes/react/blog.ts
T
Tony 5527d18de9 refactor: remove unnecessary trim/first/last (#22837)
* refactor: remove unnecessary trim/first/last

* refactor(types): allow null in DataItem.description

* refactor: remove unnecessary fallback

* refactor(types): allow null in Data.description

* refactor: remove unnecessary fallback

* refactor: remove .clone()

* refactor: refine json content text

* fIx: cognition

* fix: more fixes

* fix(route/jiemian): use api

* fix(route/jandan): housekeeping

add back maintainers from #8904

* fix(route/kcna/news): update source and target mappings

* fix(route/jandan): sanitize HTML content in titles

* refactor: remove unnecessary referer

* fix(route/jinse): regex
2026-07-27 22:23:57 +08:00

59 lines
1.6 KiB
TypeScript

import { load } from 'cheerio';
import type { DataItem, Route } from '@/types';
import cache from '@/utils/cache';
import ofetch from '@/utils/ofetch';
import { parseDate } from '@/utils/parse-date';
const handler: Route['handler'] = async () => {
const data = await ofetch('https://react.dev/blog');
const $ = load(data);
const item = (await Promise.all(
$('a[href^="/blog/"]')
.toArray()
.slice(0, 20)
.map((item) => {
const link = `https://react.dev${item.attribs.href}`;
return cache.tryGet(`react:blog:${link}`, async () => {
const data = await ofetch(link);
const $ = load(data);
return {
title: $('h1').first().text(),
link,
description: $('article div:nth-child(2)').html(),
pubDate: parseDate($('p.whitespace-pre-wrap').first().text().split(/\s+by/, 1)[0]),
};
});
})
)) as DataItem[];
return {
title: 'React Blog',
link: 'https://react.dev/blog',
language: 'en-US',
item,
};
};
export const route: Route = {
path: '/blog',
name: 'Blog',
categories: ['blog'],
maintainers: ['equt'],
example: '/react/blog',
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
handler,
};