From 0091fc84963c996c59afcad41afaf7f07ac0646d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BD=86=E4=B8=BA=E5=90=9B=E6=95=85?= Date: Sat, 4 Jan 2025 12:46:45 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20add=20feed=20for=20ruankao(=E4=B8=AD?= =?UTF-8?q?=E5=9B=BD=E8=AE=A1=E7=AE=97=E6=9C=BA=E8=81=8C=E4=B8=9A=E6=8A=80?= =?UTF-8?q?=E6=9C=AF=E8=B5=84=E6=A0=BC=E8=80=83=E8=AF=95)=20website.=20(#1?= =?UTF-8?q?8037)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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> --- lib/routes/ruankao/namespace.ts | 6 +++ lib/routes/ruankao/news.ts | 90 +++++++++++++++++++++++++++++++++ 2 files changed, 96 insertions(+) create mode 100644 lib/routes/ruankao/namespace.ts create mode 100644 lib/routes/ruankao/news.ts diff --git a/lib/routes/ruankao/namespace.ts b/lib/routes/ruankao/namespace.ts new file mode 100644 index 00000000000000..63d8e48e6d6373 --- /dev/null +++ b/lib/routes/ruankao/namespace.ts @@ -0,0 +1,6 @@ +import type { Namespace } from '@/types'; + +export const namespace: Namespace = { + name: '中国计算机职业技术资格考试', + url: 'www.ruankao.org.cn', +}; diff --git a/lib/routes/ruankao/news.ts b/lib/routes/ruankao/news.ts new file mode 100644 index 00000000000000..822b65adc1cb8d --- /dev/null +++ b/lib/routes/ruankao/news.ts @@ -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', +};