feat(/scu/scupi): Add route for SCUPI (#17542)
* Add route for SCUPI * Update _utils.ts Add image for each article
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
import type { Namespace } from '@/types';
|
||||
|
||||
export const namespace: Namespace = {
|
||||
name: '四川大学',
|
||||
url: 'www.scu.edu.cn',
|
||||
lang: 'zh-CN',
|
||||
};
|
||||
@@ -0,0 +1,63 @@
|
||||
import got from '@/utils/got';
|
||||
import { load } from 'cheerio';
|
||||
import { parseDate } from '@/utils/parse-date';
|
||||
import { config } from '@/config';
|
||||
|
||||
export async function getNotifList() {
|
||||
try {
|
||||
const response = await got.get('https://scupi.scu.edu.cn/activities/notice', {
|
||||
headers: {
|
||||
'User-Agent': config.ua,
|
||||
},
|
||||
});
|
||||
const html = response.body;
|
||||
const $ = load(html);
|
||||
|
||||
const listElement = $('body > div.wrapper > main > section > div > div > div.news > div > ul');
|
||||
return listElement
|
||||
.find('article')
|
||||
.toArray()
|
||||
.map((articleElement) => {
|
||||
const titleElement = $(articleElement).find('li > div > div.news-text > h4 > a');
|
||||
const timeElement = $(articleElement).find('li > div > div.news-text > span');
|
||||
const imageElement = $(articleElement).find('li > div > div.news-img > a > img');
|
||||
|
||||
const link = titleElement.attr('href');
|
||||
const title = titleElement.attr('title');
|
||||
const pubDate = timeElement.text().trim();
|
||||
|
||||
return {
|
||||
title,
|
||||
link,
|
||||
itunes_item_image: imageElement.attr('src'),
|
||||
pubDate: parseDate(pubDate, 'YYYY-MM-DD'),
|
||||
};
|
||||
});
|
||||
} catch {
|
||||
// console.error(error);
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
export async function getArticle(item) {
|
||||
try {
|
||||
const response = await got.get(item.link, {
|
||||
headers: {
|
||||
'User-Agent': config.ua,
|
||||
},
|
||||
});
|
||||
const html = response.body;
|
||||
const $ = load(html);
|
||||
const articleContentElement = $('body > div > main > section > div > div > div.post-content-contaier > div');
|
||||
const content = articleContentElement.html();
|
||||
const modifiedContent = content?.replace(/\n/g, '<br>');
|
||||
|
||||
item.description = modifiedContent;
|
||||
return item;
|
||||
} catch {
|
||||
// console.error(error);
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
// Warning: The author still knows nothing about javascript!
|
||||
|
||||
import { getNotifList, getArticle } from './_utils';
|
||||
import { Route } from '@/types';
|
||||
import cache from '@/utils/cache';
|
||||
|
||||
export const route: Route = {
|
||||
path: '/scupi',
|
||||
categories: ['university'],
|
||||
example: '/scu/scupi',
|
||||
parameters: {},
|
||||
features: {
|
||||
requireConfig: false,
|
||||
requirePuppeteer: false,
|
||||
antiCrawler: false,
|
||||
supportBT: false,
|
||||
supportPodcast: false,
|
||||
supportScihub: false,
|
||||
},
|
||||
name: '匹兹堡学院通知',
|
||||
maintainers: ['sitdownkevin'],
|
||||
url: 'scupi.scu.edu.cn/activities/notice',
|
||||
handler,
|
||||
description: ``,
|
||||
};
|
||||
|
||||
async function handler() {
|
||||
// feed the data to rss
|
||||
const items = await getNotifList();
|
||||
const itemsWithContent = await Promise.all(items.map((item) => cache.tryGet(item.link, () => getArticle(item))));
|
||||
|
||||
return {
|
||||
title: '四川大学匹兹堡学院',
|
||||
description: '四川大学匹兹堡学院官网通知',
|
||||
language: 'zh-cn',
|
||||
image: 'https://scupi.scu.edu.cn/wp-content/themes/scupi/img/logo.png',
|
||||
link: 'https://scupi.scu.edu.cn/',
|
||||
item: itemsWithContent,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user