feat(route): 新增新余学院官网通知及图书馆通知路由 (#20051)
* feat(route): 新余学院官网通知及图书馆通知路由 * fix: remove router * refactor(xyu): Remove paging processing logic * fix: eslint error fix --------- Co-authored-by: Tony <TonyRL@users.noreply.github.com>
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
import { Route } from '@/types';
|
||||
import ofetch from '@/utils/ofetch';
|
||||
import { load } from 'cheerio';
|
||||
import { parseDate } from '@/utils/parse-date';
|
||||
|
||||
export const route: Route = {
|
||||
path: '/library',
|
||||
categories: ['university'],
|
||||
example: '/xyu/library',
|
||||
features: {
|
||||
requireConfig: false,
|
||||
requirePuppeteer: false,
|
||||
antiCrawler: false,
|
||||
supportBT: false,
|
||||
supportPodcast: false,
|
||||
supportScihub: false,
|
||||
},
|
||||
name: '图书馆通知公告',
|
||||
maintainers: ['JinMokai'],
|
||||
handler,
|
||||
url: 'lib.xyc.edu.cn/index/tzgg.htm',
|
||||
radar: [
|
||||
{
|
||||
source: ['lib.xyc.edu.cn/index/tzgg.htm'],
|
||||
target: '/library',
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
async function handler() {
|
||||
const baseUrl = 'https://lib.xyc.edu.cn';
|
||||
const url = `${baseUrl}/index/tzgg.htm`;
|
||||
|
||||
const response = await ofetch(url);
|
||||
const $ = load(response);
|
||||
|
||||
const items = $('.text-list ul li')
|
||||
.toArray()
|
||||
.map((item) => {
|
||||
const $item = $(item);
|
||||
const $link = $item.find('a');
|
||||
const title = $link.attr('title') || $link.text().trim();
|
||||
const relativeUrl = $link.attr('href');
|
||||
const link = relativeUrl ? new URL(relativeUrl, baseUrl).href : '';
|
||||
// 提取日期
|
||||
const dateText = $item.find('.date').text().trim() || $item.text().match(/\d{4}-\d{2}-\d{2}/)?.[0] || '';
|
||||
const pubDate = parseDate(dateText, 'YYYY-MM-DD');
|
||||
|
||||
return {
|
||||
title,
|
||||
link,
|
||||
pubDate,
|
||||
description: title,
|
||||
};
|
||||
})
|
||||
.filter((item): item is NonNullable<typeof item> => Boolean(item.title && item.link));
|
||||
|
||||
return {
|
||||
title: '新余学院图书馆通知公告',
|
||||
link: url,
|
||||
item: items,
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
import type { Namespace } from '@/types';
|
||||
|
||||
export const namespace: Namespace = {
|
||||
name: '新余学院',
|
||||
url: 'xyc.edu.cn',
|
||||
lang: 'zh-CN',
|
||||
};
|
||||
@@ -0,0 +1,116 @@
|
||||
import { Route } from '@/types';
|
||||
import cache from '@/utils/cache';
|
||||
import ofetch from '@/utils/ofetch';
|
||||
import { load } from 'cheerio';
|
||||
import { parseDate } from '@/utils/parse-date';
|
||||
import timezone from '@/utils/timezone';
|
||||
|
||||
export const route: Route = {
|
||||
path: '/index/tzgg',
|
||||
categories: ['university'],
|
||||
example: '/xyu/index/tzgg',
|
||||
features: {
|
||||
requireConfig: false,
|
||||
requirePuppeteer: false,
|
||||
antiCrawler: false,
|
||||
supportBT: false,
|
||||
supportPodcast: false,
|
||||
supportScihub: false,
|
||||
},
|
||||
radar: [
|
||||
{
|
||||
source: ['www.xyc.edu.cn/index/tzgg.htm'],
|
||||
},
|
||||
],
|
||||
name: '官网通知公告',
|
||||
maintainers: ['JinMokai'],
|
||||
handler,
|
||||
url: 'www.xyc.edu.cn/index/tzgg.htm',
|
||||
};
|
||||
|
||||
async function handler() {
|
||||
const baseUrl = 'https://www.xyc.edu.cn';
|
||||
const url = `${baseUrl}/index/tzgg.htm`;
|
||||
|
||||
const response = await ofetch(url);
|
||||
if (!response) {
|
||||
return {
|
||||
title: '新余学院 - 通知公告',
|
||||
link: url,
|
||||
item: [],
|
||||
};
|
||||
}
|
||||
|
||||
const $ = load(response);
|
||||
|
||||
const list = $('.text-list ul li')
|
||||
.toArray()
|
||||
.map((item) => {
|
||||
const currentItem = $(item);
|
||||
const link = currentItem.find('a').attr('href');
|
||||
if (!link) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const title = currentItem.find('.list-tx h3').text().trim();
|
||||
const description = currentItem.find('.list-tx p').text().trim();
|
||||
const day = currentItem.find('.date p').text().trim();
|
||||
const yearMonth = currentItem.find('.date span').text().trim();
|
||||
const dateText = `${yearMonth}-${day.padStart(2, '0')}`;
|
||||
|
||||
return {
|
||||
title,
|
||||
link: new URL(link, baseUrl).href,
|
||||
description: description || title,
|
||||
pubDate: timezone(parseDate(dateText, 'YYYY-MM-DD'), +8),
|
||||
};
|
||||
})
|
||||
.filter(Boolean);
|
||||
|
||||
const items = await Promise.all(
|
||||
list.map((item) =>
|
||||
cache.tryGet(item?.link || '', async () => {
|
||||
if (!item) {
|
||||
return '';
|
||||
}
|
||||
try {
|
||||
const detailResponse = await ofetch(item?.link);
|
||||
if (!detailResponse) {
|
||||
return {
|
||||
...item,
|
||||
description: '该通知无法直接预览,请点击原文链接查看',
|
||||
};
|
||||
}
|
||||
|
||||
const $$ = load(detailResponse);
|
||||
const content = $$('.v_news_content, .content, .article-content').html();
|
||||
|
||||
if (content) {
|
||||
const $content = load(content);
|
||||
$content('a').each(function () {
|
||||
const a = $(this);
|
||||
const href = a.attr('href');
|
||||
if (href && !href.startsWith('http')) {
|
||||
a.attr('href', new URL(href, baseUrl).href);
|
||||
}
|
||||
});
|
||||
item.description = $content.html();
|
||||
}
|
||||
|
||||
return item;
|
||||
} catch {
|
||||
return {
|
||||
...item,
|
||||
description: '该通知无法直接预览,请点击原文链接查看',
|
||||
};
|
||||
}
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
return {
|
||||
title: '新余学院 - 通知公告',
|
||||
link: url,
|
||||
item: items,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user