Skip to content

Commit

Permalink
fix(routes/hrbust/news): fix docs and logical problem (#18112)
Browse files Browse the repository at this point in the history
* fix(routes/hrbust/news): fix docs and logical problem

* fix(routes/hrbust/jwzx): fix codeQL warning
  • Loading branch information
cscnk52 authored Jan 13, 2025
1 parent d69d320 commit 494fe64
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions lib/routes/hrbust/news.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { load } from 'cheerio';
import { parseDate } from '@/utils/parse-date';
import timezone from '@/utils/timezone';

const rootUrl = 'https://news.hrbust.edu.cn';
const rootUrl = 'https://news.hrbust.edu.cn/';

export const route: Route = {
path: '/news/:category?',
Expand All @@ -15,11 +15,9 @@ export const route: Route = {
handler,
example: '/hrbust/news',
parameters: { category: '栏目标识,默认为理工要闻' },
description: `
| lgyw | xwdd | zhenew | jxky | ycdt | xskc | jlhz | zsjy | djsz | zxbf | lgxb | mtlg | jzlt |
description: `| lgyw | xwdd | zhenew | jxky | ycdt | xskc | jlhz | zsjy | djsz | zxbf | lgxb | mtlg | jzlt |
| ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- |
| 理工要闻 | 新闻导读 | 综合新闻 | 教学科研 | 院处动态 | 学术科创 | 交流合作 | 招生就业 | 党建思政 | 在线播放 | 理工校报 | 媒体理工 | 讲座论坛 |
`,
| 理工要闻 | 新闻导读 | 综合新闻 | 教学科研 | 院处动态 | 学术科创 | 交流合作 | 招生就业 | 党建思政 | 在线播放 | 理工校报 | 媒体理工 | 讲座论坛 |`,
categories: ['university'],
features: {
supportRadar: true,
Expand All @@ -35,7 +33,7 @@ export const route: Route = {
async function handler(ctx) {
const { category = 'lgyw' } = ctx.req.param();

const response = await got(`${rootUrl}/${category}.htm`);
const response = await got(`${rootUrl}${category}.htm`);

const $ = load(response.data);

Expand All @@ -58,6 +56,11 @@ async function handler(ctx) {
const items = await Promise.all(
list.map((item) =>
cache.tryGet(item.link, async () => {
if (!item.link.startsWith(rootUrl)) {
item.description = '本文需跳转,请点击标题后阅读';
return item;
}

const detailResponse = await got(item.link);
const content = load(detailResponse.data);

Expand All @@ -67,15 +70,15 @@ async function handler(ctx) {
item.pubDate = pubTime;
}

item.description = content('div.v_news_content').html() || '本文需跳转,请点击标题后阅读';
item.description = content('div.v_news_content').html() || '解析正文失败';
return item;
})
)
);

return {
title: `哈尔滨理工大学新闻网 - ${bigTitle}`,
link: `${rootUrl}/${category}.htm`,
link: `${rootUrl}${category}.htm`,
item: items,
};
}

0 comments on commit 494fe64

Please sign in to comment.