feat(route): add 四川人社厅人事考试专栏 (#19799)

* feat(route): add 四川人社厅人事考试专栏

* fix(route/scpta): address code review feedback

1. Remove indentation in description table
2. Got usage to single-line style
3. Return html content instead of plain text

Refs: #19799
This commit is contained in:
Yeye 2025-08-12 19:24:49 +08:00 committed by GitHub
parent ad01222209
commit 59a757dccb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 109 additions and 0 deletions

View File

@ -0,0 +1,8 @@
import type { Namespace } from '@/types';
export const namespace: Namespace = {
name: '四川省人力资源和社会保障厅人事考试专栏',
url: 'www.scpta.com.cn',
categories: ['government'],
lang: 'zh-CN',
};

101
lib/routes/scpta/news.ts Normal file
View File

@ -0,0 +1,101 @@
import { Route } from '@/types';
import got from '@/utils/got';
import { load } from 'cheerio';
import { parseDate } from '@/utils/parse-date';
import cache from '@/utils/cache';
export const route: Route = {
path: '/news/:category',
categories: ['government'],
example: '/scpta/news/33',
parameters: {
category: {
description: '分类ID默认为`33`(工作动态)',
default: '33',
},
},
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
radar: [
{
source: ['www.scpta.com.cn/front/News/List'],
target: '/news',
},
],
name: '通知公告',
maintainers: ['Yeye-0426'], // github ID
handler,
description: `| 分类 | category_id |
|----------------------|-------------|
| | 33 |
| | 56 |
| | 57 |
| | 67 |
| | 72 |`,
};
async function handler(ctx) {
const category = ctx.req.param('category');
const baseUrl = 'https://www.scpta.com.cn';
// 构建请求URL
const url = `${baseUrl}/front/News/List/${category}`;
// 发送请求
const response = await got(url);
const $ = load(response.data);
// 解析搜索结果
const list = $('div.wrap-content li')
.toArray()
.map((item) => {
item = $(item);
return {
title: item.find('a').attr('title'),
link: `${baseUrl}${item.find('a').attr('href')}`,
pubDate: parseDate(item.find('span').text().trim()),
};
});
// 获取公告详情
const items = await Promise.all(
list.map((item) =>
cache.tryGet(item.link, async () => {
let description = '';
try {
const contentResponse = await got(item.link);
const content = load(contentResponse.data);
// 提取公告正文
description = content('div.wrap-content.news-content').html();
} catch {
// 如果详情页获取失败,使用默认描述
description = '公告内容获取失败';
}
item.description = description;
return item;
})
)
);
// 生成RSS输出
const categoryNames = {
'33': '工作动态',
'56': '公务员考试',
'57': '专业技术人员资格考试',
'67': '事业单位考试',
'72': '其它',
};
return {
title: `通知公告 - ${categoryNames[category] || '未知分类'}`,
link: url,
item: items,
};
}