feat: add MarginNote中文分享社区标签 (#6419)

This commit is contained in:
Ethan Shen 2020-12-15 19:25:16 +08:00 committed by GitHub
parent 83b959d704
commit 948f536516
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 57 additions and 0 deletions

View File

@ -81,6 +81,17 @@ pageClass: routes
<Route author="liecn" example="/gradcafe/result/computer" path="/gradcafe/result/:type" :paramsDesc="['按关键词进行搜索,如 computer']"/>
## MarginNote
### 标签
<Route author="nczitzk" example="/marginnote/tag/经验分享" path="/marginnote/tag/:id?" :paramsDesc="['标签名,见下表,默认为 经验分享']">
| 经验分享 | 论坛精华 | 待跟进反馈 | 优秀建议 | 精选回答 | 官方签名 | 自动更新 | 3674 以上版本支持 | 368 以上版本支持 | 未经验证的安全风险 | 笔记本分享 | 关键反馈 | 精选话题讨论 | 灵感盒 | 引用 |
| -------- | -------- | ---------- | -------- | -------- | -------- | -------- | ----------------- | ---------------- | ------------------ | ---------- | -------- | ------------ | ------ | ---- |
</Route>
## Mind42
### 分类

View File

@ -3698,6 +3698,9 @@ router.get('/treasury/press-releases/:category?/:title?', require('./routes/us/t
// Bandisoft
router.get('/bandisoft/:id?/:lang?', require('./routes/bandisoft/index'));
// MarginNote
router.get('/marginnote/tag/:id?', require('./routes/marginnote/tag'));
// ASML
router.get('/asml/press-releases', require('./routes/asml/press-releases'));

View File

@ -0,0 +1,43 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const id = ctx.params.id || '经验分享';
const rootUrl = 'https://bbs.marginnote.cn';
const currentUrl = `${rootUrl}/tag/${id}/l/latest.json`;
const response = await got({
method: 'get',
url: currentUrl,
});
const list = response.data.topic_list.topics.slice(0, 10).map((item) => ({
title: item.title,
link: `${rootUrl}/t/topic/${item.id}`,
pubDate: new Date(item.last_posted_at).toUTCString(),
}));
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.replace('<noscript', '<div').replace('</noscript>', '</div>'));
item.author = content('.creator').eq(0).text();
item.description = content('.post').eq(0).html();
return item;
})
)
);
ctx.state.data = {
title: `${response.data.topic_list.tags[0].name} - MarginNote 中文论坛`,
link: currentUrl,
item: items,
};
};