Files
RSSHub/lib/routes/leiphone/index.ts
T
Tony a5e2e295dc refactor: fix all get to toArray (#19000)
* refactor: fix all get

* fix(utils/common-config): charset case compare

* Revert "fix(utils/common-config): charset case compare"

This reverts commit 3c1880f2fad53ad2cafddcee7741390fd46fa3d2.

* fix: nga

* fix: notateslaapp

* fix: ps

* fix: xjtu

* fix: enforce error on restricted syntax for get calls

* fix: eslint

* fix: more eslint
2025-05-04 05:24:53 +08:00

42 lines
1.0 KiB
TypeScript

import { Route } from '@/types';
import cache from '@/utils/cache';
import got from '@/utils/got';
import { load } from 'cheerio';
import utils from './utils';
export const route: Route = {
path: '/:do?/:keyword?',
radar: [
{
source: ['leiphone.com/'],
target: '',
},
],
name: 'Unknown',
maintainers: [],
handler,
url: 'leiphone.com/',
};
async function handler(ctx) {
const todo = ctx.req.param('do') ?? '';
const keyword = ctx.req.param('keyword') ?? '';
const rootUrl = 'https://www.leiphone.com';
const url = `${rootUrl}/${todo}/${keyword}`;
const res = await got.get(url);
const $ = load(res.data);
const list = $('.word > h3 > a')
.slice(0, 10)
.toArray()
.map((e) => $(e).attr('href'));
const items = await utils.ProcessFeed(list, cache);
return {
title: `雷峰网${todo === 'category' ? ` ${keyword}` : ''}`,
description: '雷峰网 - 读懂智能&未来',
link: url,
item: items,
};
}