diff --git a/docs/other.md b/docs/other.md index 503782030d..a037fb73b1 100644 --- a/docs/other.md +++ b/docs/other.md @@ -263,11 +263,11 @@ type 为 all 时,category 参数不支持 cost 和 free ### 通知 - + -| 遴选通知 | 综合项目专栏 | 常见问题解答 | 录取公告 | -| -------- | ------------ | ------------ | -------- | -| lxtz | xmzl | wtjd | lqgg | +| 遴选通知 | 综合项目专栏 | 常见问题解答 | 录取公告 | 新闻资讯 | 新闻公告 | +| -------- | ------------ | ------------ | -------- | -------- | -------- | +| lxtz | xmzl | wtjd | lqgg | xwzx | xwgg | diff --git a/docs/reading.md b/docs/reading.md index f78bebe823..b9212ad739 100644 --- a/docs/reading.md +++ b/docs/reading.md @@ -216,6 +216,18 @@ count 的取值范围为 1-12,为防止请求次数过多,推荐设置为 5 | | /biobio/science/ecology-environment | | | /biobio/gnjz | +## 生物谷 + +### 所有栏目 + + + +具体栏目编号,去网站上看标签 + +| 网址 | 对应路由 | +| ------------------------------- | ------------------ | +| | /shengwugu/biology | + ## 书趣阁 ### 小说更新 @@ -267,15 +279,3 @@ count 的取值范围为 1-12,为防止请求次数过多,推荐设置为 5 ### 主页 - -## 生物谷 - -### 所有栏目 - - - -具体栏目编号,去网站上看标签 - -| 网址 | 对应路由 | -| -------- | -------- | -| http://news.bioon.com/biology | /shengwugu/biology | diff --git a/docs/university.md b/docs/university.md index 53a44f9abf..bd0a3a88ce 100644 --- a/docs/university.md +++ b/docs/university.md @@ -158,6 +158,16 @@ pageClass: routes ## 北京林业大学 +### 绿色新闻网 + + + +| 绿色要闻 | 校园动态 | 教学科研 | 党建思政 | 一周排行 | +| -------- | -------- | -------- | -------- | -------- | +| lsyw | lsxy | jxky | djsz | yzph | + + + ### 研究生院培养动态 diff --git a/lib/router.js b/lib/router.js index 0659dec07c..c2b5c696ad 100644 --- a/lib/router.js +++ b/lib/router.js @@ -558,6 +558,7 @@ router.get('/zdfx', require('./routes/galgame/zdfx')); // 北京林业大学 router.get('/bjfu/grs', require('./routes/universities/bjfu/grs')); router.get('/bjfu/jwc/:type', require('./routes/universities/bjfu/jwc/index')); +router.get('/bjfu/news/:type', require('./routes/universities/bjfu/news/index')); // 北京理工大学 router.get('/bit/jwc', require('./routes/universities/bit/jwc/jwc')); diff --git a/lib/routes/csc/notice.js b/lib/routes/csc/notice.js index 68d3c26184..de0c8c3cde 100644 --- a/lib/routes/csc/notice.js +++ b/lib/routes/csc/notice.js @@ -22,6 +22,14 @@ const typeMap = { name: '录取公告', url: '/chuguo/list/28', }, + xwzx: { + name: '新闻资讯', + url: '/news', + }, + xwgg: { + name: '新闻公告', + url: '/news/gonggao', + }, }; module.exports = async (ctx) => { diff --git a/lib/routes/universities/bjfu/news/index.js b/lib/routes/universities/bjfu/news/index.js new file mode 100644 index 0000000000..c72c46ce82 --- /dev/null +++ b/lib/routes/universities/bjfu/news/index.js @@ -0,0 +1,55 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const util = require('./utils'); +const iconv = require('iconv-lite'); // 转码 + +module.exports = async (ctx) => { + const type = ctx.params.type; + let title, path; + switch (type) { + case 'lsyw': + title = '绿色要闻'; + path = 'lsyw/'; + break; + case 'xydt': + title = '校园动态'; + path = 'lsxy/'; + break; + case 'jxky': + title = '教学科研'; + path = 'jxky/'; + break; + case 'djsz': + title = '党建思政'; + path = 'djsz/'; + break; + case 'yzph': + title = '一周排行'; + path = 'yzph/'; + break; + default: + title = '绿色要闻'; + path = 'lsyw/'; + } + const base = 'http://news.bjfu.edu.cn/' + path; + + const response = await got({ + method: 'get', + responseType: 'buffer', // 转码 + url: base, + }); + + const data = iconv.decode(response.data, 'gb2312'); // 转码 + const $ = cheerio.load(data); + + const list = $('.news_ul li').slice(0, 10).get(); + + const result = await util.ProcessFeed(base, list, ctx.cache); // 感谢@hoilc指导 + + ctx.state.data = { + title: '北林新闻- ' + title, + link: 'http://news.bjfu.edu.cn/' + path, + description: '绿色新闻网 - ' + title, + item: result, + }; +}; diff --git a/lib/routes/universities/bjfu/news/utils.js b/lib/routes/universities/bjfu/news/utils.js new file mode 100644 index 0000000000..232bba3b3a --- /dev/null +++ b/lib/routes/universities/bjfu/news/utils.js @@ -0,0 +1,63 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const iconv = require('iconv-lite'); // 转码 + +// 完整文章页 +async function load(link) { + const response = await got.get(link, { + responseType: 'buffer', + }); + + const data = iconv.decode(response.data, 'gb2312'); // 转码 + + // 加载文章内容 + const $ = cheerio.load(data); + + // 解析日期 + const date = new Date( + $('.article') + .text() + .match(/\d{4}-\d{2}-\d{2}/) + ); + + const timeZone = 8; + const serverOffset = date.getTimezoneOffset() / 60; + const pubDate = new Date(date.getTime() - 60 * 60 * 1000 * (timeZone + serverOffset)).toUTCString(); + + // 提取内容 + const description = $('.article_con').html(); + + // 返回解析的结果 + return { description, pubDate }; +} + +const ProcessFeed = async (base, list, caches) => + // 使用 Promise.all() 进行 async 并发 + await Promise.all( + // 遍历每一篇文章 + list.map(async (item) => { + const $ = cheerio.load(item); + + const $title = $('a'); + // 还原相对链接为绝对链接 + const itemUrl = new URL($title.attr('href'), base).href; // 感谢@hoilc指导 + + // 列表上提取到的信息 + const single = { + title: $title.text(), + link: itemUrl, + author: '绿色新闻网', + guid: itemUrl, + }; + + // 使用tryGet方法从缓存获取内容。 + // 当缓存中无法获取到链接内容的时候,则使用load方法加载文章内容。 + const other = await caches.tryGet(itemUrl, async () => await load(itemUrl)); + + // 合并解析后的结果集作为该篇文章最终的输出结果 + return Promise.resolve(Object.assign({}, single, other)); + }) + ); +module.exports = { + ProcessFeed, +};