添加知晓程序 (#878)

#864
This commit is contained in:
Henry Wang 2018-10-14 09:36:39 +01:00 committed by DIYgod
parent bcabc04156
commit e84e880e2e
3 changed files with 70 additions and 0 deletions

View File

@ -1854,6 +1854,16 @@ IATA 国际航空运输协会机场代码, 参见[维基百科 国际航空运
<route name="观止" author="Andiedie" example="/guanzhi" path="/guanzhi"/>
### 知晓程序
<route name="文章" author="HenryQW" example="/miniapp/article/cloud" path="/miniapp/article/:category" :paramsDesc="['分类名称']">
| 全部 | 小程序资讯 | 知晓云 | 小程序推荐 | 榜单 | 晓组织 | 新能力 | 小程序问答 |
| ---- | ---------- | ------ | -------------- | ---- | ------ | ---------- | ---------- |
| all | news | cloud | recommendation | rank | group | capability | qa |
</route>
### 后续
<route name="后续" author="fengkx" example="/houxu/events/38" path="/houxu/:type/:id" :paramsDesc="['类型', 'ID']"/>

View File

@ -626,6 +626,9 @@ router.get('/pediy/topic/:category?/:type?', require('./routes/pediy/topic'));
// 观止(每日一文)
router.get('/guanzhi', require('./routes/guanzhi/guanzhi'));
// 知晓程序
router.get('/miniapp/article/:category', require('./routes/miniapp/article'));
// 后续
router.get('/houxu/:type/:id', require('./routes/houxu/houxu'));

57
routes/miniapp/article.js Normal file
View File

@ -0,0 +1,57 @@
const axios = require('../../utils/axios');
module.exports = async (ctx) => {
const category = ctx.params.category.toLowerCase();
let host = `https://minapp.com/api/v5/trochili/post/?category=${category}&post_type=article&limit=10`;
if (category === 'all') {
host = 'https://minapp.com/api/v5/trochili/post/?post_type=article&limit=10';
}
let title;
switch (category) {
case 'news':
title = '小程序资讯';
break;
case 'cloud':
title = '知晓云';
break;
case 'recommendation':
title = '小程序推荐';
break;
case 'rank':
title = '榜单';
break;
case 'group':
title = '晓组织';
break;
case 'capability':
title = '新能力';
break;
case 'qa':
title = '小程序问答';
break;
default:
break;
}
const response = await axios.get(host);
const list = response.data.objects;
const out = list.map((item) => ({
title: item.title,
link: `https://minapp.com/article/${item.id}`,
author: item.created_by.nickname,
description: item.content,
pubDate: new Date(item.created_at * 1000),
}));
ctx.state.data = {
title: `知晓程序${title ? ' - ' + title : ''}`,
description: '知晓程序 | 一扫即用的小程序大全',
link: `https://minapp.com/article/?page=1&category=${category}`,
item: out,
};
};