Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/DIYgod/RSSHub
Browse files Browse the repository at this point in the history
  • Loading branch information
dddaniel1 committed Dec 14, 2024
2 parents 00dcea2 + 3a8d34e commit 6c21fc3
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 4 deletions.
7 changes: 7 additions & 0 deletions lib/routes/daoxuan/namespace.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import type { Namespace } from '@/types';

export const namespace: Namespace = {
name: '道宣的窝',
url: 'daoxuan.cc',
lang: 'zh-CN',
};
43 changes: 43 additions & 0 deletions lib/routes/daoxuan/rss.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { Route } from '@/types';
import got from '@/utils/got';
import { load } from 'cheerio';
import { parseDate } from '@/utils/parse-date';

export const route: Route = {
path: '/',
categories: ['blog'],
example: '/daoxuan',
radar: [
{
source: ['daoxuan.cc/'],
},
],
name: '推荐阅读文章',
maintainers: ['dx2331lxz'],
url: 'daoxuan.cc/',
handler,
};

async function handler() {
const url = 'https://daoxuan.cc/';
const response = await got({ method: 'get', url });
const $ = load(response.data);
const items = $('div.recent-post-item')
.toArray()
.map((item) => {
item = $(item);
const a = item.find('a.article-title').first();
const timeElement = item.find('time').first();
return {
title: a.attr('title'),
link: `https://daoxuan.cc${a.attr('href')}`,
pubDate: parseDate(timeElement.attr('datetime')),
description: a.attr('title'),
};
});
return {
title: '道宣的窝',
link: url,
item: items,
};
}
3 changes: 2 additions & 1 deletion lib/routes/hrbust/namespace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { Namespace } from '@/types';

export const namespace: Namespace = {
name: '哈尔滨理工大学',
url: 'jwzx.hrbust.edu.cn',
url: 'hrbust.edu.cn',
categories: ['university'],
lang: 'zh-CN',
};
81 changes: 81 additions & 0 deletions lib/routes/hrbust/news.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import { Route, ViewType } 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?',
name: '新闻网',
url: 'news.hrbust.edu.cn',
maintainers: ['cscnk52'],
handler,
example: '/hrbust/news',
parameters: { category: '栏目标识,默认为理工要闻' },
description: `
| lgyw | xwdd | zhenew | jxky | ycdt | xskc | jlhz | zsjy | djsz | zxbf | lgxb | mtlg | jzlt |
| ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- |
| 理工要闻 | 新闻导读 | 综合新闻 | 教学科研 | 院处动态 | 学术科创 | 交流合作 | 招生就业 | 党建思政 | 在线播放 | 理工校报 | 媒体理工 | 讲座论坛 |
`,
categories: ['university'],
features: {
supportRadar: true,
},
radar: [
{
source: ['news.hrbust.edu.cn/:category.htm'],
},
],
view: ViewType.Notifications,
};

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

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,
};
}
6 changes: 3 additions & 3 deletions lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,9 +247,9 @@ interface RouteItem {
}

interface Route extends RouteItem {
ja?: NamespaceItem;
zh?: NamespaceItem;
'zh-TW'?: NamespaceItem;
ja?: RouteItem;
zh?: RouteItem;
'zh-TW'?: RouteItem;
}

export type { Route };
Expand Down

0 comments on commit 6c21fc3

Please sign in to comment.