Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add feed for ruankao(中国计算机职业技术资格考试) website. #18037

Merged
merged 19 commits into from
Jan 4, 2025
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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',
};
92 changes: 92 additions & 0 deletions lib/routes/ruankao/news.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
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 = await Promise.all(
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,
};
})
);
PrinOrange marked this conversation as resolved.
Show resolved Hide resolved

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: `软考新闻动态`,
PrinOrange marked this conversation as resolved.
Show resolved Hide resolved
source: ['www.ruankao.org.cn/index/work', 'www.ruankao.org.cn'],
target: `/ruankao/news`,
PrinOrange marked this conversation as resolved.
Show resolved Hide resolved
},
],
example: '/ruankao/news',
};
Loading