Skip to content

Commit

Permalink
fix(route/xaut): update new homepage (#17194)
Browse files Browse the repository at this point in the history
  • Loading branch information
mocusez authored Oct 19, 2024
1 parent a495a6c commit 1d77ba3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 21 deletions.
33 changes: 13 additions & 20 deletions lib/routes/xaut/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { Route } from '@/types';
import cache from '@/utils/cache';
import got from '@/utils/got';
import timezone from '@/utils/timezone';
import { parseDate } from '@/utils/parse-date';
import { load } from 'cheerio';

export const route: Route = {
path: '/index/:category?',
categories: ['university'],
example: '/xaut/index/tzgg',
parameters: { category: '通知类别,默认为通知公告' },
parameters: { category: '通知类别,默认为学校新闻' },
features: {
requireConfig: false,
requirePuppeteer: false,
Expand All @@ -20,19 +21,19 @@ export const route: Route = {
name: '学校主页',
maintainers: ['mocusez'],
handler,
description: `| 通知公告 | 校园要闻 | 媒体播报 | 学术活动 |
| :------: | :------: | :------: | :------: |
| tzgg | xyyw | mtbd | xshd |`,
description: `| 学校新闻 | 砥志研思 | 立德树人 | 传道授业 | 校闻周知 |
| :------: | :------: | :------: | :------: | :------: |
| xxxw | dzys | ldsr | cdsy | xwzz |`,
};

async function handler(ctx) {
let category = ctx.req.param('category');
const dic_html = { tzgg: 'tzgg.htm', xyyw: 'xyyw.htm', mtbd: 'mtbd1.htm', xshd: 'xshd.htm' };
const dic_title = { tzgg: '通知公告', xyyw: '校园要闻', mtbd: '媒体播报', xshd: '学术活动' };
const dic_html = { xxxw: 'xxxw.htm', dzys: 'dzys.htm', ldsr: 'ldsr.htm', cdsy: 'cdsy.htm', xwzz: 'xwzz.htm' };
const dic_title = { xxxw: '学校新闻', dzys: '砥志研思', ldsr: '立德树人', cdsy: '传道授业', xwzz: '校闻周知' };

// 设置默认值
if (dic_title[category] === undefined) {
category = 'tzgg';
category = 'xxxw';
}

const response = await got({
Expand All @@ -42,26 +43,18 @@ async function handler(ctx) {
const data = response.body;
const $ = load(data);

// 这个列表指通知公告详情列表
const list = $('.newslist_block ul a')
const list = $('div.nlist ul li')
.map((_, item) => {
item = $(item);
const temp = item.find('span').text();

// link原来长这样:'../info/1196/13990.htm'
const link = item.attr('href').replace(/^\.\./, 'http://www.xaut.edu.cn');
let date = parseDate(temp.slice(-10, -1), 'YYYY-MM-DD');
let title = temp.slice(0, -10);

if (category === 'xshd') {
date = parseDate(temp.slice(-11, -1).replace('年', '-').replace('月', '-').replace('日', ''), 'YYYY-MM-DD');
title = temp.slice(0, -11);
}
const link = item.find('a').attr('href').replace(/^\.\./, 'http://www.xaut.edu.cn');
const pubDate = timezone(parseDate(item.find('div.time').text().trim()), +8);
const title = item.find('h5').text();

return {
title,
link,
pubDate: date,
pubDate,
};
})
.get();
Expand Down
2 changes: 1 addition & 1 deletion lib/routes/xaut/namespace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ import type { Namespace } from '@/types';

export const namespace: Namespace = {
name: '西安理工大学',
url: 'index.xaut.edu.cn',
url: 'www.xaut.edu.cn',
};

0 comments on commit 1d77ba3

Please sign in to comment.