From ad0876c6e02296b6024d659c14621243635fe57c 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 13:08:57 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20Add=20pacilution.com=20(=E6=99=AE?= =?UTF-8?q?=E4=B8=96=E7=A4=BE=E4=BC=9A=E7=A7=91=E5=AD=A6=E7=A0=94=E7=A9=B6?= =?UTF-8?q?=E6=89=80)=20router=20(#18036)?= 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 router for pacilution.com * fix: fix the url concat Co-authored-by: Tony * fix: remove unused protocol Co-authored-by: Tony * fix: remove unnecessary promise wrapping. * fix: add radar --------- Co-authored-by: pull[bot] <39814207+pull[bot]@users.noreply.github.com> --- lib/routes/pacilution/latest.ts | 102 +++++++++++++++++++++++++++++ lib/routes/pacilution/namespace.ts | 6 ++ 2 files changed, 108 insertions(+) create mode 100644 lib/routes/pacilution/latest.ts create mode 100644 lib/routes/pacilution/namespace.ts diff --git a/lib/routes/pacilution/latest.ts b/lib/routes/pacilution/latest.ts new file mode 100644 index 00000000000000..fa65b069ceaae6 --- /dev/null +++ b/lib/routes/pacilution/latest.ts @@ -0,0 +1,102 @@ +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'; +import iconv from 'iconv-lite'; + +const BASE_URL = 'http://www.pacilution.com/'; + +const handler: Route['handler'] = async () => { + // Fetch the target page + const response = await got({ + method: 'get', + url: BASE_URL, + responseType: 'buffer', + }); + const $ = load(iconv.decode(response.data, 'gb2312')); + + // Select all list items containing target information + const ITEM_SELECTOR = 'ul[class*="ullbxwnew"] > li'; + const listItems = $(ITEM_SELECTOR); + + // Map through each list item to extract details + const contentLinkList = listItems.toArray().map((element) => { + const title = $(element).find('a').text(); + const relativeHref = $(element).find('a').attr('href') || ''; + const link = `${BASE_URL}${relativeHref}`; + + return { + title, + link, + }; + }); + + return { + title: '普世社会科学研究网最新文章', + description: '普世社会科学研究网首页上不同板块的最新文章汇总集合', + link: BASE_URL, + image: 'http://www.pacilution.com/img/top_banner.jpg', + item: ( + await Promise.all( + contentLinkList.map((item) => + cache.tryGet(item.link, async () => { + try { + const CONTENT_SELECTOR = '#MyContent'; + const DATE_SELECTOR = 'td[class*="con_info"] > span'; + const response = await got({ + method: 'get', + url: item.link, + responseType: 'buffer', + }); + const targetPage = load(iconv.decode(response.data, 'gb2312')); + const content = targetPage(CONTENT_SELECTOR).html() || ''; + const date = parseDate(targetPage(DATE_SELECTOR).text().trim().replaceAll('日', '')).toISOString(); + return { + title: item.title, + pubDate: date, + link: item.link, + description: content, + category: ['journal'], + guid: item.link, + id: item.link, + image: 'http://www.pacilution.com/img/top_banner.jpg', + content, + updated: date, + language: 'zh-cn', + }; + } catch { + return null as unknown as DataItem; + } + }) + ) + ) + ).filter((item) => item !== null) as DataItem[], + allowEmpty: true, + language: 'zh-cn', + feedLink: 'https://rsshub.app/pacilution/latest', + id: 'https://rsshub.app/pacilution/latest', + }; +}; + +export const route: Route = { + path: '/latest', + name: '最新文章', + maintainers: ['PrinOrange'], + handler, + categories: ['journal'], + features: { + requireConfig: false, + requirePuppeteer: false, + antiCrawler: false, + supportBT: false, + supportPodcast: false, + supportScihub: false, + }, + example: '/pacilution/latest', + radar: [ + { + source: ['www.pacilution.com'], + }, + ], +}; diff --git a/lib/routes/pacilution/namespace.ts b/lib/routes/pacilution/namespace.ts new file mode 100644 index 00000000000000..8951709049d0e5 --- /dev/null +++ b/lib/routes/pacilution/namespace.ts @@ -0,0 +1,6 @@ +import type { Namespace } from '@/types'; + +export const namespace: Namespace = { + name: '普世社会科学研究所', + url: 'www.pacilution.com', +};