diff --git a/docs/university.md b/docs/university.md index ad317e055e..2c66997097 100644 --- a/docs/university.md +++ b/docs/university.md @@ -645,6 +645,18 @@ category 列表: 部分文章需要经过统一身份认证后才能阅读全文。 ::: +## 哈尔滨工业大学(深圳) + +### 哈尔滨工业大学(深圳) - 新闻中心 + + + +| 校区要闻 | 媒体报道 | 通知公告 | 综合新闻 | 校园动态 | 讲座论坛 | 热点专题 | +| -------- | -------- | -------- | -------- | -------- | -------- | -------- | +| id-116 | id-80 | id-74 | id-75 | id-77 | id-78 | id-79 | + + + ## 哈尔滨工业大学(威海) ### 今日工大 - 通知公告 diff --git a/lib/router.js b/lib/router.js index 8b0becd54d..b77e169c5d 100644 --- a/lib/router.js +++ b/lib/router.js @@ -636,6 +636,9 @@ router.get('/hhu/libNewsc', require('./routes/universities/hhu/libNewsc')); router.get('/hit/jwc', require('./routes/universities/hit/jwc')); router.get('/hit/today/:category', require('./routes/universities/hit/today')); +// 哈尔滨工业大学(深圳) +router.get('/hitsz/article/:category?', require('./routes/universities/hitsz/article')); + // 哈尔滨工业大学(威海) router.get('/hitwh/today', require('./routes/universities/hitwh/today')); diff --git a/lib/routes/universities/hitsz/article.js b/lib/routes/universities/hitsz/article.js new file mode 100644 index 0000000000..ee11f0379d --- /dev/null +++ b/lib/routes/universities/hitsz/article.js @@ -0,0 +1,44 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + const host = 'http://www.hitsz.edu.cn'; + const category = ctx.params.category || 'id-74'; + + const response = await got.get(`${host}/article/${category}.html`); + const $ = cheerio.load(response.data); + const category_name = $('div.title_page').text().trim(); + + const lists = $('.mainside_news ul li') + .map((_, el) => ({ + title: $('a', el).text().trim(), + link: `${host}${$('a', el).attr('href')}`, + pubDate: new Date($('span[class=date]', el).text()).toUTCString(), + })) + .get(); + + const items = await Promise.all( + lists.map( + async (item) => + await ctx.cache.tryGet(item.link, async () => { + const response = await got.get(item.link); + const $ = cheerio.load(response.data); + item.description = + $('div.detail').html() && + $('div.detail') + .html() + .replace(/src="\//g, `src="${new URL('.', host).toString()}"`) + .replace(/href="\//g, `href="${new URL('.', host).toString()}"`) + .trim(); + return item; + }) + ) + ); + + ctx.state.data = { + title: '哈尔滨工业大学(深圳)-' + category_name, + link: `${host}/article/${category}.html`, + description: '哈尔滨工业大学(深圳)-' + category_name, + item: items, + }; +};