diff --git a/.eslintrc b/.eslintrc index 127632529..0d09c5cde 100644 --- a/.eslintrc +++ b/.eslintrc @@ -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 } } diff --git a/README.md b/README.md index c875626ec..dbb338e40 100644 --- a/README.md +++ b/README.md @@ -268,6 +268,8 @@ RSSHub 是一个轻量、易于扩展的 RSS 生成器,可以给任何奇奇 - 文章 - 大连工业大学 - 教务处新闻 +- ifanr + - AppSolution diff --git a/docs/README.md b/docs/README.md index acc7e7cf8..886452d9e 100644 --- a/docs/README.md +++ b/docs/README.md @@ -2222,3 +2222,13 @@ type,分类 路由: `/mygalgame` 参数: 无 + +## 爱范儿 ifanr + +### AppSolution + +举例: + +路由: `/ifanr/appso` + +参数: 无 diff --git a/router.js b/router.js index 73a0a82a3..b8bfab54f 100755 --- a/router.js +++ b/router.js @@ -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; diff --git a/routes/ifanr/appso.js b/routes/ifanr/appso.js new file mode 100644 index 000000000..19cd7fb2e --- /dev/null +++ b/routes/ifanr/appso.js @@ -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, + }; +};