mirror of
https://github.com/DIYgod/RSSHub.git
synced 2026-10-24 12:15:32 +08:00
feat: Add pacilution.com (普世社会科学研究所) router (#18036)
* 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 <TonyRL@users.noreply.github.com> * fix: remove unused protocol Co-authored-by: Tony <TonyRL@users.noreply.github.com> * fix: remove unnecessary promise wrapping. * fix: add radar --------- Co-authored-by: pull[bot] <39814207+pull[bot]@users.noreply.github.com>
This commit is contained in:
@@ -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'],
|
||||
},
|
||||
],
|
||||
};
|
||||
@@ -0,0 +1,6 @@
|
||||
import type { Namespace } from '@/types';
|
||||
|
||||
export const namespace: Namespace = {
|
||||
name: '普世社会科学研究所',
|
||||
url: 'www.pacilution.com',
|
||||
};
|
||||
Reference in New Issue
Block a user