From 90c6432838599d3821eeb2b5e1d9fa1f2f1e2dd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BD=86=E4=B8=BA=E5=90=9B=E6=95=85?= Date: Thu, 23 Jan 2025 05:38:21 +0800 Subject: [PATCH] fix(route/ruankao): Remove font presetting and other details. (#18160) * fix: remove font presetting and other details. * fix: add anti-crawler tag. * fix: migrate jsdom to cheerio. * fix: fix news-router name. --- lib/routes/ruankao/news.ts | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/lib/routes/ruankao/news.ts b/lib/routes/ruankao/news.ts index 822b65adc1..720a1ada45 100644 --- a/lib/routes/ruankao/news.ts +++ b/lib/routes/ruankao/news.ts @@ -1,11 +1,26 @@ -import { DataItem, Route } from '@/types'; +import type { 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 removeFontPresetting = (html: string = ''): string => { + const $ = load(html); + $('[style]').each((_, element) => { + const style = $(element).attr('style') || ''; + const cleanedStyle = style.replaceAll(/font-family:[^;]*;?/gi, '').trim(); + $(element).attr('style', cleanedStyle || null); + }); + $('style').each((_, styleElement) => { + const cssText = $(styleElement).html() || ''; + const cleanedCssText = cssText.replaceAll(/font-family:[^;]*;?/gi, ''); + $(styleElement).html(cleanedCssText); + }); + + return $.html(); +}; + const handler: Route['handler'] = async () => { // Fetch the index page const { data: listResponse } = await got(BASE_URL); @@ -30,8 +45,8 @@ const handler: Route['handler'] = async () => { }); return { - title: '计算机职业技术资格考试(软考)最新动态', - description: '计算机职业技术资格考试(软考)网站最新动态和消息推送', + title: '计算机职业技术资格考试(软考)动态', + description: '计算机职业技术资格考试(软考)消息推送', link: BASE_URL, image: 'https://bm.ruankao.org.cn/asset/image/public/logo.png', item: (await Promise.all( @@ -40,7 +55,7 @@ const handler: Route['handler'] = async () => { const CONTENT_SELECTOR = '#contentTxt'; const { data: contentResponse } = await got(item.link); const contentPage = load(contentResponse); - const content = contentPage(CONTENT_SELECTOR).html() || ''; + const content = removeFontPresetting(contentPage(CONTENT_SELECTOR).html() || ''); return { title: item.title, pubDate: item.date, @@ -52,13 +67,13 @@ const handler: Route['handler'] = async () => { image: 'https://bm.ruankao.org.cn/asset/image/public/logo.png', content, updated: item.date, - language: 'zh-cn', + language: 'zh-CN', }; }) ) )) as DataItem[], allowEmpty: true, - language: 'zh-cn', + language: 'zh-CN', feedLink: 'https://rsshub.app/ruankao/news', id: 'https://rsshub.app/ruankao/news', }; @@ -66,14 +81,15 @@ const handler: Route['handler'] = async () => { export const route: Route = { path: '/news', - name: '软考最新动态', + name: '软考动态', + description: '**注意:** 官方网站限制了国外网络请求,可能需要通过部署在中国大陆内的 RSSHub 实例访问。', maintainers: ['PrinOrange'], handler, categories: ['study'], features: { requireConfig: false, requirePuppeteer: false, - antiCrawler: false, + antiCrawler: true, supportBT: false, supportPodcast: false, supportScihub: false, @@ -81,7 +97,7 @@ export const route: Route = { }, radar: [ { - title: '软考新闻动态', + title: '计算机职业技术资格考试(软考)动态', source: ['www.ruankao.org.cn/index/work', 'www.ruankao.org.cn'], target: `/news`, },