Skip to content

Commit

Permalink
feat(route): add 哈尔滨理工大学新闻网
Browse files Browse the repository at this point in the history
  • Loading branch information
cscnk52 committed Dec 11, 2024
1 parent e764739 commit 45a70db
Showing 1 changed file with 84 additions and 0 deletions.
84 changes: 84 additions & 0 deletions lib/routes/hrbust/news.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import { Route } from '@/types';
import cache from '@/utils/cache';
import got from '@/utils/got';
import { load } from 'cheerio';
import { parseDate } from '@/utils/parse-date';
import timezone from '@/utils/timezone';

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

export const route: Route = {
path: '/news/:category?',
categories: ['university'],
example: '/hrbust/news/lgyw',
parameters: { category: '栏目标识,默认为理工新闻' },
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
radar: [
{
source: ['news.hrbust.edu.cn/:category.htm'],
},
],
name: '哈尔滨理工大学新闻网',
maintainers: ['cscnk52'],
handler,
description: `
| lgyw | xwdd | zhenew | jxky | ycdt | xskc | jlhz | zsjy | djsz | zxbf | lgxb | mtlg | jzlt |
| ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- |
| 理工要闻 | 新闻导读 | 综合新闻 | 教学科研 | 院处动态 | 学术科创 | 交流合作 | 招生就业 | 党建思政 | 在线播放 | 理工校报 | 媒体理工 | 讲座论坛 |
`,
};

async function handler(ctx) {
const category = ctx.req.param('category') || 'lgyw';

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

const $ = load(response.data);

const bigTitle = $('title').text().split('-')[0].trim();

const list = $('div.main-liebiao-con-left-bottom li[id^=line_u10]')
.toArray()
.map((item) => {
const element = $(item);
const link = new URL(element.find('a').attr('href'), rootUrl).href;
const pubDateText = element.find('span').text().trim();
const pubDate = pubDateText ? timezone(parseDate(pubDateText), +8) : null;
return {
title: element.find('a').text().trim(),
pubDate,
link,
};
});

const items = await Promise.all(
list.map((item) =>
cache.tryGet(item.link, async () => {
const detailResponse = await got(item.link);
const content = load(detailResponse.data);

const dateText = content('p.xinxi span:contains("日期时间:")').text().replace('日期时间:', '').trim();
const pubTime = dateText ? timezone(parseDate(dateText), +8) : null;
if (pubTime) {
item.pubDate = pubTime;
}

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

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

0 comments on commit 45a70db

Please sign in to comment.