Files
RSSHub/lib/routes/aliyun/developer/group.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

68 lines
2.0 KiB
TypeScript

import { Route } from '@/types';
import got from '@/utils/got';
import { load } from 'cheerio';
import { parseDate } from '@/utils/parse-date';
export const route: Route = {
path: '/developer/group/:type',
categories: ['programming'],
example: '/aliyun/developer/group/alitech',
parameters: { type: '对应技术领域分类' },
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
radar: [
{
source: ['developer.aliyun.com/group/:type'],
},
],
name: '开发者社区 - 主题',
maintainers: ['umm233'],
handler,
};
async function handler(ctx) {
const type = ctx.req.param('type');
const link = `https://developer.aliyun.com/group/${type}`;
// 发起 HTTP GET 请求
const response = await got({
method: 'get',
url: link,
});
const data = response.data;
// 使用 cheerio 加载返回的 HTML
const $ = load(data);
const title = $('div[class="header-information-title"]')
.contents()
.filter((element) => element.nodeType === 3)
.text()
.trim();
const desc = $('div[class="header-information"]').find('span').last().text().trim();
const list = $('ul[class^="content-tab-list"] > li');
return {
title: `阿里云开发者社区-${title}`,
link,
description: desc,
item: list.toArray().map((item) => {
item = $(item);
const desc = item.find('.question-desc');
const description = item.find('.browse').text() + ' ' + desc.find('.answer').text();
return {
title: item.find('.question-title').text().trim() || item.find('a p').text().trim(),
link: item.find('a').attr('href'),
pubDate: parseDate(item.find('.time').text()),
description,
};
}),
};
}