From c72f9d4bbf22527c4db053e84a518bc05695f7e5 Mon Sep 17 00:00:00 2001 From: Ethan Shen Date: Sat, 26 Dec 2020 13:49:08 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20add=20=E4=B8=AD=E5=9B=BD=E7=A7=91?= =?UTF-8?q?=E5=AD=A6=E9=99=A2=E9=9D=92=E5=B9=B4=E5=88=9B=E6=96=B0=E4=BF=83?= =?UTF-8?q?=E8=BF=9B=E4=BC=9A=E6=9C=80=E6=96=B0=E5=8D=9A=E6=96=87=20(#6519?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/new-media.md | 6 +++++ lib/router.js | 3 +++ lib/routes/yicas/blog.js | 53 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+) create mode 100644 lib/routes/yicas/blog.js diff --git a/docs/new-media.md b/docs/new-media.md index 61c4f4322d..22ec42b400 100644 --- a/docs/new-media.md +++ b/docs/new-media.md @@ -2032,6 +2032,12 @@ column 为 third 时可选的 category: +## 中国科学院青年创新促进会 + +### 最新博文 + + + ## 中国劳工观察 ### 调查报告 diff --git a/lib/router.js b/lib/router.js index 4da06027ff..669ffb210c 100644 --- a/lib/router.js +++ b/lib/router.js @@ -3744,6 +3744,9 @@ router.get('/idaily/today', require('./routes/idaily/index')); // 北屋 router.get('/northhouse/:category?', require('./routes/northhouse/index')); +// 中国科学院青年创新促进会 +router.get('/yicas/blog', require('./routes/yicas/blog')); + // 九三学社 router.get('/93/:category?', require('./routes/93/index')); diff --git a/lib/routes/yicas/blog.js b/lib/routes/yicas/blog.js new file mode 100644 index 0000000000..84f60e479c --- /dev/null +++ b/lib/routes/yicas/blog.js @@ -0,0 +1,53 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const iconv = require('iconv-lite'); + +module.exports = async (ctx) => { + const rootUrl = 'http://yicas.cn'; + const currentUrl = `${rootUrl}/portal.php?mod=blog`; + const response = await got({ + method: 'get', + url: currentUrl, + responseType: 'buffer', + }); + + const $ = cheerio.load(iconv.decode(response.data, 'gbk')); + + const list = $('tr td a[title]') + .slice(0, 15) + .map((_, item) => { + item = $(item); + return { + title: item.text(), + link: item.attr('href'), + pubDate: new Date(item.next().text()).toUTCString(), + }; + }) + .get(); + + const items = await Promise.all( + list.map( + async (item) => + await ctx.cache.tryGet(item.link, async () => { + const detailResponse = await got({ + method: 'get', + url: item.link, + responseType: 'buffer', + }); + const content = cheerio.load(iconv.decode(detailResponse.data, 'gbk')); + + item.author = content('.xs2').text(); + item.description = content('#blog_article').html(); + item.pubDate = new Date(content('.xg1').eq(5).text()).toUTCString(); + + return item; + }) + ) + ); + + ctx.state.data = { + title: $('title').text(), + link: currentUrl, + item: items, + }; +};