* chore(deps-dev): bump eslint-plugin-unicorn from 64.0.0 to 65.0.0 Bumps [eslint-plugin-unicorn](https://github.com/sindresorhus/eslint-plugin-unicorn) from 64.0.0 to 65.0.0. - [Release notes](https://github.com/sindresorhus/eslint-plugin-unicorn/releases) - [Commits](https://github.com/sindresorhus/eslint-plugin-unicorn/compare/v64.0.0...v65.0.0) --- updated-dependencies: - dependency-name: eslint-plugin-unicorn dependency-version: 65.0.0 dependency-type: direct:development update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> * fix: no-array-from-fill * fix: unicorn-js/no-duplicate-set-values * fix: no-this-outside-of-class * fix: no-unnecessary-nested-ternary * fix: prefer-array-last-methods * fix: prefer-queue-microtask * fix: prefer-split-limit * fix: no-array-from-fill * fix: no-unused-array-method-return * fix: prefer-single-call * fix: prefer-includes-over-repeated-comparisons * fix: consistent-compound-words * fix: prefer-includes-over-repeated-comparisons * chore: add eslint-plugin-unicorn v65 recommended preset * fix: correct duration parsing logic in parseDuration function * fix: update oxlint-disable --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Tony <TonyRL@users.noreply.github.com>
59 lines
1.6 KiB
TypeScript
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().trim(),
|
|
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,
|
|
};
|