diff --git a/lib/routes/gdufs/namespace.ts b/lib/routes/gdufs/namespace.ts new file mode 100644 index 00000000000000..78419f7dcb1f72 --- /dev/null +++ b/lib/routes/gdufs/namespace.ts @@ -0,0 +1,7 @@ +import type { Namespace } from '@/types'; + +export const namespace: Namespace = { + name: '广东外语外贸大学', + url: 'gdufs.edu.cn', + lang: 'zh-CN', +}; diff --git a/lib/routes/gdufs/news.ts b/lib/routes/gdufs/news.ts new file mode 100644 index 00000000000000..05429661306a07 --- /dev/null +++ b/lib/routes/gdufs/news.ts @@ -0,0 +1,98 @@ +import { Route } from '@/types'; +import { load } from 'cheerio'; +import cache from '@/utils/cache'; +import got from '@/utils/got'; +import { parseDate } from '@/utils/parse-date'; + +const site = 'https://www.gdufs.edu.cn'; + +export const route: Route = { + path: '/news', + categories: ['university'], + example: '/gdufs/news', + parameters: {}, + features: { + requireConfig: false, + requirePuppeteer: false, + antiCrawler: false, + supportBT: false, + supportPodcast: false, + supportScihub: false, + }, + radar: [ + { + source: ['www.gdufs.edu.cn/gwxw/gwxw1.htm', 'www.gdufs.edu.cn/'], + }, + ], + name: '新闻', + maintainers: ['gz4zzxc'], + handler, + url: 'www.gdufs.edu.cn/gwxw/gwxw1.htm', +}; + +async function handler() { + const link = 'https://www.gdufs.edu.cn/gwxw/gwxw1.htm'; + + const response = await got(link); + const $ = load(response.body); + const list = $('ul.list_luntan li'); + + const items = await Promise.all( + list.toArray().map(async (element) => { + const item = $(element); + const href = item.find('a').attr('href') || ''; + const title = item.find('h5').text().trim(); + const day = item.find('h3').text().trim(); + const yearMonth = item.find('h6').text().trim(); + const dateString = yearMonth + '/' + day; + const fullLink = href.startsWith('http') ? href : new URL(href, site).href; + + const pubDate = parseDate(dateString).toUTCString(); + + const content = await cache.tryGet(fullLink, async () => { + try { + const articleRes = await got(fullLink); + const $$ = load(articleRes.body); + const description = $$('.v_news_content').html()?.trim() || ''; + + // 提取作者信息 + let author = ''; + const authorSpans = $$('.nav01 h6 .ll span'); + authorSpans.each((_, el) => { + const text = $$(el).text().trim(); + if (text.includes('责任编辑:')) { + author = text.replace('责任编辑:', '').trim(); + } else if (text.includes('文字:')) { + author = text.replace('文字:', '').trim(); + } + }); + + return { + description, + author, + }; + } catch { + return { + description: '内容获取失败。', + author: '', + }; + } + }); + + return { + title, + link: fullLink, + description: content.description, + pubDate, + author: content.author, + }; + }) + ); + + return { + title: '广东外语外贸大学-新闻', + link, + description: '广东外语外贸大学-新闻', + item: items, + }; +} diff --git a/lib/routes/gdufs/xwxy/xwxy-news.ts b/lib/routes/gdufs/xwxy/xwxy-news.ts new file mode 100644 index 00000000000000..0b0b065af3e62f --- /dev/null +++ b/lib/routes/gdufs/xwxy/xwxy-news.ts @@ -0,0 +1,96 @@ +import { Route } from '@/types'; +import { load } from 'cheerio'; +import cache from '@/utils/cache'; +import got from '@/utils/got'; +import { parseDate } from '@/utils/parse-date'; + +export const route: Route = { + path: '/xwxy-news', + categories: ['university'], + example: '/gdufs/xwxy-news', + parameters: {}, + features: { + requireConfig: false, + requirePuppeteer: false, + antiCrawler: false, + supportBT: false, + supportPodcast: false, + supportScihub: false, + }, + radar: [ + { + source: ['xwxy.gdufs.edu.cn/xwzx/xyxw', 'xwxy.gdufs.edu.cn/'], + }, + ], + name: '新闻学院-学院新闻', + maintainers: ['gz4zzxc'], + handler, + url: 'xwxy.gdufs.edu.cn/xwzx/xyxw', +}; + +async function handler() { + const BASE_URL = 'https://xwxy.gdufs.edu.cn'; + const link = `${BASE_URL}/xwzx/xyxw.htm`; + + // 获取列表页面 + const response = await got(link); + if (!response.body) { + throw new Error('No response body'); + } + const $ = load(response.body); + const list = $('div.flex-center a.clearfix'); + + const items = list.toArray().map((element) => { + const item = $(element); + const href = item.attr('href') || ''; + const dateText = item.find('i').text().trim(); + const pubDate = parseDate(dateText).toUTCString(); + return { + title: item.find('h5').text().trim(), + link: href.startsWith('http') ? href : new URL(href, BASE_URL).href, + pubDate, + }; + }); + + // 获取文章详情 + const fetchArticleDetail = async (item) => { + const contentData = await cache.tryGet(item.link, async () => { + try { + const articleResponse = await got(item.link); + if (!articleResponse.body) { + throw new Error('No article body'); + } + const $$ = load(articleResponse.body); + const content = $$('#vsb_content .v_news_content').html() || ''; + const authors = $$('.show01 p i') + .toArray() + .map((el) => $$(el).text().trim()); + + return { + description: content, + author: authors.join(' '), + }; + } catch { + return { + description: '无法获取内容', + author: '', + }; + } + }); + + return { + ...item, + description: contentData.description, + author: contentData.author, + }; + }; + + const enhancedItems = await Promise.all(items.map((item) => fetchArticleDetail(item))); + + return { + title: '广外新传学院-学院新闻', + link, + description: '广东外语外贸大学新闻与传播学院官网-学院新闻', + item: enhancedItems, + }; +}