Skip to content

Commit

Permalink
feat: add CATTI feed (全国翻译专业资格水平考试) (#18041)
Browse files Browse the repository at this point in the history
* Update package.json

* Update package.json

* feat: add RSS subscription for (NWMU) Northwestern Minzu University.

* fix: fix array generation forms for dom-parser.

* fix: fix url replacing behavior.

* fix: fix cover images, typos and maintainer.

* fix: remove router from deprecated routers.

* fix: fix router name and example.

* fix: fix items limit.

* fix: fix date parser.

* fix: use cache for the RSS data.

* fix: typo

* feat: add catti router.

* fix: remove unused promise wrapping

* fix: remove unnecessary param check.

* fix: add radar

---------

Co-authored-by: pull[bot] <39814207+pull[bot]@users.noreply.github.com>
  • Loading branch information
PrinOrange and pull[bot] authored Jan 4, 2025
1 parent 33443f6 commit f3c5b3a
Show file tree
Hide file tree
Showing 2 changed files with 126 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/routes/catti/namespace.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import type { Namespace } from '@/types';

export const namespace: Namespace = {
name: '全国翻译专业资格水平考试 (CATTI)',
url: 'www.catticenter.com',
};
120 changes: 120 additions & 0 deletions lib/routes/catti/news.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
import { DataItem, Route } from '@/types';
import cache from '@/utils/cache';
import got from '@/utils/got';
import { parseDate } from '@/utils/parse-date';
import { load } from 'cheerio';

type NewsCategory = {
title: string;
description: string;
};

const NEWS_TYPES: Record<string, NewsCategory> = {
ggl: {
title: '通知公告',
description: 'CATTI 考试通知和公告',
},
ywdt: {
title: '要闻动态',
description: 'CATTI 考试要闻动态',
},
zxzc: {
title: '最新政策',
description: 'CATTI 考试最新政策',
},
};

const handler: Route['handler'] = async (context) => {
const category = context.req.param('category');

const BASE_URL = `https://www.catticenter.com/${category}`;

// Fetch the index page
const { data: listPage } = await got(BASE_URL);
const $ = load(listPage);

// Select all list items containing news information
const ITEM_SELECTOR = 'ul.ui-card.ui-card-a > li';
const listItems = $(ITEM_SELECTOR);

// Map through each list item to extract details
const contentLinkList = listItems.toArray().map((element) => {
const date = $(element).find('span.ui-right-time').text();
const title = $(element).find('a').attr('title')!;
const relativeLink = $(element).find('a').attr('href')!;
const absoluteLink = `https://www.catticenter.com${relativeLink}`;
const formattedDate = parseDate(date);
return {
date: formattedDate,
title,
link: absoluteLink,
};
});

return {
title: NEWS_TYPES[category].title,
description: NEWS_TYPES[category].description,
link: BASE_URL,
image: 'https://www.catticenter.com/img/applogo.png',
item: (await Promise.all(
contentLinkList.map((item) =>
cache.tryGet(item.link, async () => {
const CONTENT_SELECTOR = 'div.ui-article-cont';
const { data: contentResponse } = await got(item.link);
const contentPage = load(contentResponse);
const content = contentPage(CONTENT_SELECTOR).html() || '';
return {
title: item.title,
pubDate: item.date,
link: item.link,
description: content,
category: ['study'],
guid: item.link,
id: item.link,
image: 'https://www.catticenter.com/img/applogo.png',
content,
updated: item.date,
language: 'zh-cn',
};
})
)
)) as DataItem[],
allowEmpty: true,
language: 'zh-cn',
feedLink: 'https://rsshub.app/ruankao/news',
id: 'https://rsshub.app/ruankao/news',
};
};

export const route: Route = {
path: '/news/:category',
name: 'CATTI 考试消息',
maintainers: ['PrinOrange'],
description: `
| Category | 标题 | 描述 |
|-----------|------------|--------------------|
| ggl | 通知公告 | CATTI 考试通知和公告 |
| ywdt | 要闻动态 | CATTI 考试要闻动态 |
| zxzc | 最新政策 | CATTI 考试最新政策 |
`,
handler,
categories: ['study'],
parameters: {
category: '消息分类名,可在下面的描述中找到。',
},
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
supportRadar: true,
},
example: '/catti/news/zxzc',
radar: [
{
source: ['www.catticenter.com/:category'],
},
],
};

0 comments on commit f3c5b3a

Please sign in to comment.