+5
-1
@@ -2564,4 +2564,8 @@ board 和 build 可在[这里](http://api.ineal.me/tss/status)查看
|
||||
|
||||
### 扇贝
|
||||
|
||||
<route name="打卡" author="DIYgod" example="/shanbay/checkin/ddwej" path="/shanbay/checkin/:id" :paramsDesc="['用户 id']" />
|
||||
<route name="打卡" author="DIYgod" example="/shanbay/checkin/ddwej" path="/shanbay/checkin/:id" :paramsDesc="['用户 id']" />
|
||||
|
||||
### 36kr
|
||||
|
||||
<route name="搜索文章" author="xyqfer" example="/36kr/search/article/8%E7%82%B91%E6%B0%AA" path="/36kr/search/article/:keyword" :paramsDesc="['关键字']" />
|
||||
|
||||
@@ -914,4 +914,7 @@ router.get('/facebook/page/:id', require('./routes/facebook/page'));
|
||||
// 停电通知
|
||||
router.get('/tingdiantz/95598/:orgNo/:provinceNo/:outageStartTime/:outageEndTime/:scope?', require('./routes/tingdiantz/95598'));
|
||||
|
||||
// 36kr
|
||||
router.get('/36kr/search/article/:keyword', require('./routes/36kr/search/article'));
|
||||
|
||||
module.exports = router;
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
const axios = require('../../../utils/axios');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const { keyword = '' } = ctx.params;
|
||||
const response = await axios({
|
||||
method: 'get',
|
||||
url: `https://36kr.com/pp/api/search/entity-search?page=1&per_page=20&sort=date&entity_type=post&keyword=${encodeURIComponent(keyword)}`,
|
||||
});
|
||||
|
||||
const load = async (link) => {
|
||||
const response = await axios.get(link);
|
||||
const data = JSON.parse(response.data.match(/<script>window\.initialState=(.*)<\/script>/)[1]) || null;
|
||||
const description = data ? data.articleDetail.articleDetailData.data.content : '';
|
||||
return { description };
|
||||
};
|
||||
const items = await Promise.all(
|
||||
response.data.data.items.map(async (item) => {
|
||||
const link = `https://www.36kr.com/p/${item.id}`;
|
||||
const single = {
|
||||
title: item.title,
|
||||
link,
|
||||
pubDate: new Date(item.published_at).toUTCString(),
|
||||
};
|
||||
|
||||
const other = await ctx.cache.tryGet(link, async () => await load(link));
|
||||
return Promise.resolve(Object.assign({}, single, other));
|
||||
})
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: `36kr - ${keyword}`,
|
||||
link: `https://www.36kr.com/search/articles/${encodeURIComponent(keyword)}`,
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user