feat: add 印象识堂 (#6205)

This commit is contained in:
Ethan Shen 2020-11-24 20:00:21 +08:00 committed by GitHub
parent a32f318beb
commit a2d5914869
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 108 additions and 0 deletions

View File

@ -304,6 +304,22 @@ pageClass: routes
</Route>
## 印象识堂
### 印象剪藏
<Route author="nczitzk" example="/yinxiang/note" path="/yinxiang/note" />
### 卡片清单
<Route author="nczitzk" example="/yinxiang/card/32" path="/yinxiang/card/:id?" :paramsDesc="['卡片 id见下表默认为每周收藏排行榜・TOP5']">
| 每周收藏排行榜・TOP5 | 每周热门「读书笔记」榜 TOP5 | 【印象话题】如何提高记忆力? | 【印象话题】选择的悖论 | 【印象专题】如何一秒洞察问题本质? | 「识堂开讲」5 位嘉宾精华笔记大放送 | 【印象话题】培养专注力的 5 个步骤 | 🎁购物清单主题活动获奖结果 |
| -------------------- | --------------------------- | ---------------------------- | ---------------------- | ---------------------------------- | ---------------------------------- | --------------------------------- | -------------------------- |
| 32 | 33 | 100 | 101 | 103 | 104 | 105 | 106 |
</Route>
## 英中协会
### 奖学金

View File

@ -3508,4 +3508,8 @@ router.get('/uisdc/news', require('./routes/uisdc/news'));
router.get('/uisdc/zt/:title?', require('./routes/uisdc/zt'));
router.get('/uisdc/topic/:title?/:sort?', require('./routes/uisdc/topic'));
// 印象识堂
router.get('/yinxiang/note', require('./routes/yinxiang/note'));
router.get('/yinxiang/card/:id?', require('./routes/yinxiang/card'));
module.exports = router;

View File

@ -0,0 +1,46 @@
const got = require('@/utils/got');
module.exports = async (ctx) => {
const id = ctx.params.id || '32';
const apiUrl = `https://app.yinxiang.com/third/discovery/client/restful/public/discovery/card-holder?cardHolderId=${id}`;
const response = await got({
method: 'get',
url: apiUrl,
});
const list = response.data.card.map((item) => ({
title: item.title,
link: item.url,
author: item.userNickname,
}));
const items = await Promise.all(
list.map(
async (item) =>
await ctx.cache.tryGet(item.link, async () => {
const detailResponse = await got({
method: 'get',
url: `https://app.yinxiang.com/third/discovery/client/restful/public/blog-note?noteGuid=${item.link.split('/note/')[1]}`,
});
item.pubDate = new Date(parseInt(detailResponse.data.blogNote.publishTime)).toUTCString();
const description = detailResponse.data.blogNote.htmlContent;
if (description.indexOf('<?xml') < 0) {
item.description = description;
} else {
item.description = description.match(/<en-note>(.*)<\/en-note>/)[1];
}
return item;
})
)
);
ctx.state.data = {
title: `${response.data.name} - 印象识堂`,
link: 'https://www.yinxiang.com/everhub/',
item: items,
};
};

View File

@ -0,0 +1,42 @@
const got = require('@/utils/got');
module.exports = async (ctx) => {
const apiUrl = 'https://app.yinxiang.com/third/discovery/client/restful/public/v2/discovery/homepage?notePageSize=20';
const response = await got({
method: 'get',
url: apiUrl,
});
const list = response.data.blogNote.slice(0, 5).map((item) => ({
title: item.title,
link: `https://www.yinxiang.com/everhub/note/${item.noteGuid}`,
pubDate: new Date(parseInt(item.publishTime)).toUTCString(),
}));
const items = await Promise.all(
list.map(
async (item) =>
await ctx.cache.tryGet(item.link, async () => {
const detailResponse = await got({
method: 'get',
url: `https://app.yinxiang.com/third/discovery/client/restful/public/blog-note?noteGuid=${item.link.split('/note/')[1]}`,
});
const description = detailResponse.data.blogNote.htmlContent;
if (description.indexOf('<?xml') < 0) {
item.description = description;
} else {
item.description = description.match(/<en-note>(.*)<\/en-note>/)[1];
}
return item;
})
)
);
ctx.state.data = {
title: '印象剪藏 - 印象识堂',
link: 'https://www.yinxiang.com/everhub/',
item: items,
};
};