feat: add 一亩三分地论坛博客 (#6361)
This commit is contained in:
parent
924f68d3a8
commit
368ffdf2c6
31
docs/bbs.md
31
docs/bbs.md
|
|
@ -642,6 +642,37 @@ pageClass: routes
|
|||
:::
|
||||
</Route>
|
||||
|
||||
### 博客
|
||||
|
||||
<Route author="nczitzk" example="/1point3acres/blog" path="/1point3acres/blog/:category?" :paramsDesc="['分类,见下表,可在对应分类页 URL 中找到']">
|
||||
|
||||
| 分类 | 分类名 |
|
||||
| ---------- | --------------------------------------------------------------------- |
|
||||
| 全部 | |
|
||||
| 一亩三分地 | 一亩三分地 |
|
||||
| 论坛精华 | 一亩三分地 - 论坛精华 |
|
||||
| 咨询服务 | 咨询服务 |
|
||||
| 学校院系 | 学校院系信息 |
|
||||
| 找工求职 | 如何找工作 |
|
||||
| 美国经济 | 如何找工作 - 美国经济与就业 |
|
||||
| 杂谈其他 | 其他类别 |
|
||||
| 抄袭 | 其他类别 - 抄袭 |
|
||||
| 直播 | 其他类别 - 直播 |
|
||||
| 热门专业 | eecsmis 统计金工等热门专业 |
|
||||
| EECSMIS | eecsmis 统计金工等热门专业 - eecsmis 专业 |
|
||||
| 数据科学 | eecsmis 统计金工等热门专业 - 数据科学 |
|
||||
| 统计金工 | eecsmis 统计金工等热门专业 - 生物统计金融工程公共健康生物技术制药行业 |
|
||||
| 留学申请 | 留学申请信息 |
|
||||
| GT 考试 | 留学申请信息 - gt 考试 |
|
||||
| 定位 | 留学申请信息 - 定位 |
|
||||
| 文书写作 | 留学申请信息 - 文书写作 |
|
||||
| 面试 | 留学申请信息 - 面试 |
|
||||
| 移民绿卡 | 移民办绿卡 |
|
||||
| 美国学习 | 美国学习 |
|
||||
| 美国生活 | 美国生活 |
|
||||
|
||||
</Route>
|
||||
|
||||
## 直播吧
|
||||
|
||||
### 子论坛
|
||||
|
|
|
|||
|
|
@ -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'));
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
};
|
||||
};
|
||||
Loading…
Reference in New Issue