Files
RSSHub/lib/routes/p-articles/contributors.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

54 lines
1.5 KiB
TypeScript

import { Route } from '@/types';
import ofetch from '@/utils/ofetch';
import { load } from 'cheerio';
import cache from '@/utils/cache';
import { rootUrl, ProcessFeed } from './utils';
export const route: Route = {
path: '/contributors/:author',
categories: ['reading'],
example: '/p-articles/contributors/黃衍仁',
parameters: { author: '虛詞作者, 可在作者页面 URL 找到' },
name: '虛詞作者',
maintainers: ['Insomnia1437'],
handler,
radar: [
{
source: ['p-articles.com/contributors/:author'],
},
],
};
async function handler(ctx) {
const authorName: string = ctx.req.param('author');
const authorUrl = new URL(`/contributors/${authorName}`, rootUrl).href;
const response = await ofetch(authorUrl);
const $ = load(response);
const list = $('div.contect_box_05in > a')
.toArray()
.map((element) => {
const info = {
title: $(element).find('h3').text().trim(),
link: new URL($(element).attr('href'), rootUrl).href,
};
return info;
});
const items = await Promise.all(
list.map((info) =>
cache.tryGet(info.link, async () => {
const response = await ofetch(info.link);
// const $ = load(response);
return ProcessFeed(info, response);
})
)
);
return {
title: '虚词 p-articles',
link: authorUrl,
item: items,
language: 'zh-cn',
};
}