Add ifanr appsolution (#562)

This commit is contained in:
Henry Wang
2018-08-29 10:27:08 +08:00
committed by DIYgod
parent dc72fc4cd9
commit d18a507190
5 changed files with 60 additions and 1 deletions
+2 -1
View File
@@ -50,6 +50,7 @@
"no-trailing-spaces": 1,
"quotes": [1, "single"],
"no-control-regex": 0,
"prettier/prettier": 0
"prettier/prettier": 0,
"no-await-in-loop": 1
}
}
+2
View File
@@ -268,6 +268,8 @@ RSSHub 是一个轻量、易于扩展的 RSS 生成器,可以给任何奇奇
- 文章
- 大连工业大学
- 教务处新闻
- ifanr
- AppSolution
</details>
+10
View File
@@ -2222,3 +2222,13 @@ type,分类
路由: `/mygalgame`
参数: 无
## 爱范儿 ifanr <Author uid="HenryQW"/>
### AppSolution
举例: <https://rsshub.app/ifanr/appso>
路由: `/ifanr/appso`
参数: 无
+3
View File
@@ -473,4 +473,7 @@ router.get('/mygalgame', require('./routes/galgame/mygalgame'));
// DPU
router.get('/dpu/jiaowu/:type?', require('./routes/dpu/jiaowu'));
// ifanr
router.get('/ifanr/appso', require('./routes/ifanr/appso'));
module.exports = router;
+43
View File
@@ -0,0 +1,43 @@
const axios = require('../../utils/axios');
const cheerio = require('cheerio');
const host = 'http://www.ifanr.com/app';
module.exports = async (ctx) => {
const response = await axios.get(host);
const $ = cheerio.load(response.data);
const list = $('h3 a')
.map((i, e) => $(e).attr('href'))
.get();
const out = await Promise.all(
list.map(async (itemUrl) => {
const cache = await ctx.cache.get(itemUrl);
if (cache) {
return Promise.resolve(JSON.parse(cache));
}
const response = await axios.get(itemUrl);
const $ = cheerio.load(response.data);
const title = $('h1').text();
const single = {
title,
link: itemUrl,
author: $('.c-article-header-meta__category').html(),
description: $('article').html(),
pubDate: new Date($('.c-article-header-meta__time').attr('date-timestamp')),
};
ctx.cache.set(itemUrl, JSON.stringify(single), 24 * 60 * 60);
return Promise.resolve(single);
})
);
ctx.state.data = {
title: 'AppSo : 让手机更好用的数字生活媒体',
link: host,
item: out,
};
};