From 368ffdf2c60ee6a07fae188126bf8352545ba973 Mon Sep 17 00:00:00 2001 From: Ethan Shen Date: Mon, 7 Dec 2020 02:15:09 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20add=20=E4=B8=80=E4=BA=A9=E4=B8=89?= =?UTF-8?q?=E5=88=86=E5=9C=B0=E8=AE=BA=E5=9D=9B=E5=8D=9A=E5=AE=A2=20(#6361?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/bbs.md | 31 +++++++++++++++++++ lib/router.js | 1 + lib/routes/1point3acres/blog.js | 53 +++++++++++++++++++++++++++++++++ 3 files changed, 85 insertions(+) create mode 100644 lib/routes/1point3acres/blog.js diff --git a/docs/bbs.md b/docs/bbs.md index 247302125..550b4eb8d 100644 --- a/docs/bbs.md +++ b/docs/bbs.md @@ -642,6 +642,37 @@ pageClass: routes ::: +### 博客 + + + +| 分类 | 分类名 | +| ---------- | --------------------------------------------------------------------- | +| 全部 | | +| 一亩三分地 | 一亩三分地 | +| 论坛精华 | 一亩三分地 - 论坛精华 | +| 咨询服务 | 咨询服务 | +| 学校院系 | 学校院系信息 | +| 找工求职 | 如何找工作 | +| 美国经济 | 如何找工作 - 美国经济与就业 | +| 杂谈其他 | 其他类别 | +| 抄袭 | 其他类别 - 抄袭 | +| 直播 | 其他类别 - 直播 | +| 热门专业 | eecsmis 统计金工等热门专业 | +| EECSMIS | eecsmis 统计金工等热门专业 - eecsmis 专业 | +| 数据科学 | eecsmis 统计金工等热门专业 - 数据科学 | +| 统计金工 | eecsmis 统计金工等热门专业 - 生物统计金融工程公共健康生物技术制药行业 | +| 留学申请 | 留学申请信息 | +| GT 考试 | 留学申请信息 - gt 考试 | +| 定位 | 留学申请信息 - 定位 | +| 文书写作 | 留学申请信息 - 文书写作 | +| 面试 | 留学申请信息 - 面试 | +| 移民绿卡 | 移民办绿卡 | +| 美国学习 | 美国学习 | +| 美国生活 | 美国生活 | + + + ## 直播吧 ### 子论坛 diff --git a/lib/router.js b/lib/router.js index 0ee95feba..63e2ba918 100644 --- a/lib/router.js +++ b/lib/router.js @@ -1616,6 +1616,7 @@ router.get('/vocus/publication/:id', require('./routes/vocus/publication')); router.get('/vocus/user/:id', require('./routes/vocus/user')); // 一亩三分地 1point3acres +router.get('/1point3acres/blog/:category?', require('./routes/1point3acres/blog')); router.get('/1point3acres/user/:id/threads', require('./routes/1point3acres/threads')); router.get('/1point3acres/user/:id/posts', require('./routes/1point3acres/posts')); router.get('/1point3acres/offer/:year?/:major?/:school?', require('./routes/1point3acres/offer')); diff --git a/lib/routes/1point3acres/blog.js b/lib/routes/1point3acres/blog.js new file mode 100644 index 000000000..b1cea5d13 --- /dev/null +++ b/lib/routes/1point3acres/blog.js @@ -0,0 +1,53 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + const category = ctx.params.category || ''; + + const rootUrl = 'https://www.1point3acres.com'; + const currentUrl = `${rootUrl}/${category === '' ? 'BlogPosts' : `category/${category.replace(/-/g, '/')}`}`; + const response = await got({ + method: 'get', + url: currentUrl, + }); + const $ = cheerio.load(response.data); + + const list = $('.mybloglist h2 a') + .slice(0, 10) + .map((_, item) => { + item = $(item); + return { + title: item.text(), + link: item.attr('href'), + }; + }) + .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, + }); + const content = cheerio.load(detailResponse.data); + + content('h2, .meta_tags, .pagination, .subinfopost, #comments').remove(); + + item.description = content('.post').html(); + item.pubDate = new Date(detailResponse.data.match(/"datePublished":"(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\+00:00)","dateModified":/)[1]).toUTCString(); + + return item; + }) + ) + ); + + const title = $('title').text().split(' | ')[0]; + + ctx.state.data = { + title: `${title === 'BlogPosts' ? '全部' : title} - 一亩三分地论坛博客`, + link: currentUrl, + item: items, + }; +};