Skip to content

Commit

Permalink
feat: add feed for ruankao(中国计算机职业技术资格考试) website. (#18037)
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 feed for ruankao(中国计算机职业技术资格考试) website.

* fix: remove unused promise wrapping.

* fix: rewrite to literal string.

* fix: remove unnecessary namespace prefix.

---------

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 f3c5b3a commit 0091fc8
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/routes/ruankao/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: '中国计算机职业技术资格考试',
url: 'www.ruankao.org.cn',
};
90 changes: 90 additions & 0 deletions lib/routes/ruankao/news.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
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';

const BASE_URL = 'https://www.ruankao.org.cn/index/work';

const handler: Route['handler'] = async () => {
// Fetch the index page
const { data: listResponse } = await got(BASE_URL);
const $ = load(listResponse);

// Select all list items containing news information
const ITEM_SELECTOR = 'ul[class*="newsList"] > li';
const listItems = $(ITEM_SELECTOR);

// Map through each list item to extract details
const contentLinkList = listItems.toArray().map((element) => {
const date = $(element).find('label.time').text().trim().slice(1, -1);
const title = $(element).find('a').attr('title')!;
const link = $(element).find('a').attr('href')!;

const formattedDate = parseDate(date);
return {
date: formattedDate,
title,
link,
};
});

return {
title: '计算机职业技术资格考试(软考)最新动态',
description: '计算机职业技术资格考试(软考)网站最新动态和消息推送',
link: BASE_URL,
image: 'https://bm.ruankao.org.cn/asset/image/public/logo.png',
item: (await Promise.all(
contentLinkList.map((item) =>
cache.tryGet(item.link, async () => {
const CONTENT_SELECTOR = '#contentTxt';
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://bm.ruankao.org.cn/asset/image/public/logo.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',
name: '软考最新动态',
maintainers: ['PrinOrange'],
handler,
categories: ['study'],
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
supportRadar: true,
},
radar: [
{
title: '软考新闻动态',
source: ['www.ruankao.org.cn/index/work', 'www.ruankao.org.cn'],
target: `/news`,
},
],
example: '/ruankao/news',
};

0 comments on commit 0091fc8

Please sign in to comment.