From e5e2368fe06f221ff0470775c1cbd453795a1d25 Mon Sep 17 00:00:00 2001 From: Ch3n4y Date: Thu, 21 May 2026 13:51:27 +0800 Subject: [PATCH] feat(route): add itsec news (#22066) * feat(route): add itsec news * fix(route): preserve itsec titles --------- Co-authored-by: Ch3n4y --- lib/routes/itsec/namespace.ts | 7 +++ lib/routes/itsec/news.ts | 91 +++++++++++++++++++++++++++++++++++ 2 files changed, 98 insertions(+) create mode 100644 lib/routes/itsec/namespace.ts create mode 100644 lib/routes/itsec/news.ts diff --git a/lib/routes/itsec/namespace.ts b/lib/routes/itsec/namespace.ts new file mode 100644 index 000000000..6b5a5120c --- /dev/null +++ b/lib/routes/itsec/namespace.ts @@ -0,0 +1,7 @@ +import type { Namespace } from '@/types'; + +export const namespace: Namespace = { + name: '中国信息安全测评中心', + url: 'www.itsec.gov.cn', + categories: ['government'], +}; diff --git a/lib/routes/itsec/news.ts b/lib/routes/itsec/news.ts new file mode 100644 index 000000000..6677ffec0 --- /dev/null +++ b/lib/routes/itsec/news.ts @@ -0,0 +1,91 @@ +import { load } from 'cheerio'; + +import type { Route } from '@/types'; +import cache from '@/utils/cache'; +import got from '@/utils/got'; +import { parseDate } from '@/utils/parse-date'; +import timezone from '@/utils/timezone'; + +const rootUrl = 'https://www.itsec.gov.cn'; +const currentUrl = `${rootUrl}/zxxw/index.html`; + +export const route: Route = { + path: '/news', + categories: ['government'], + example: '/itsec/news', + features: { + requireConfig: false, + requirePuppeteer: false, + antiCrawler: false, + supportBT: false, + supportPodcast: false, + supportScihub: false, + }, + name: '新闻发布', + maintainers: ['ch3n4y'], + radar: [ + { + source: ['www.itsec.gov.cn/zxxw/index.html', 'www.itsec.gov.cn/zxxw/'], + target: '/news', + }, + ], + handler, +}; + +async function handler() { + const { data: response } = await got(currentUrl); + const $ = load(response); + + const list = $('.listbox .list-every li') + .toArray() + .map((item) => { + const $item = $(item); + const $link = $item.find('a').first(); + const title = $link.text() || $link.prop('title'); + const href = $link.prop('href'); + const date = $item.find('span').first().text().trim(); + + if (!title || !href) { + return null; + } + + const link = new URL(href, currentUrl).href; + + return { + title, + link, + pubDate: date ? timezone(parseDate(date), 8) : undefined, + }; + }) + .filter((item): item is { title: string; link: string; pubDate?: Date } => item !== null); + + const items = await Promise.all( + list.map((item) => + cache.tryGet(item.link, async () => { + const { data: detailResponse } = await got(item.link); + const $detail = load(detailResponse); + + const title = $detail('.article-tit').text() || item.title; + const date = $detail('.article .date').text().trim(); + const author = $detail('.article .from').last().text().trim(); + + $detail('#js_content script, #js_content style').remove(); + const description = $detail('#js_content .TRS_Editor').html() || $detail('#js_content').html(); + + return { + title, + link: item.link, + description, + author, + pubDate: date ? timezone(parseDate(date), 8) : item.pubDate, + }; + }) + ) + ); + + return { + title: '中国信息安全测评中心 - 新闻发布', + link: currentUrl, + item: items, + }; +}