feat: add 爱Q生活网 (#5498)

Co-authored-by: Henry Wang <hi@henry.wang>
This commit is contained in:
Ethan Shen
2020-08-22 21:03:14 +01:00
committed by GitHub
co-authored by Henry Wang
parent ce6f5dae4a
commit c06806bc15
3 changed files with 62 additions and 0 deletions
+6
View File
@@ -55,6 +55,12 @@ pageClass: routes
</Route>
## 爱 Q 生活网
### 最近更新
<Route author="nczitzk" example="/iqshw/latest" path="/iqshw/latest"/>
## BOOKSOURCE.STORE
### 书源仓库更新
+3
View File
@@ -3081,6 +3081,9 @@ router.get('/souyun/today', require('./routes/souyun/today'));
// 生物谷
router.get('/bioon/latest', require('./routes/bioon/latest'));
// 爱Q生活网
router.get('/iqshw/latest', require('./routes/iqshw/latest'));
// JustRun
router.get('/justrun', require('./routes/justrun/index'));
+53
View File
@@ -0,0 +1,53 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const iconv = require('iconv-lite');
module.exports = async (ctx) => {
const rootUrl = 'https://www.iqshw.com';
const currentUrl = `${rootUrl}/post/new_100/`;
const response = await got({
method: 'get',
url: currentUrl,
responseType: 'buffer',
});
const $ = cheerio.load(iconv.decode(response.data, 'gb2312'));
const list = $('ul.list-item li')
.slice(0, 15)
.map((_, item) => {
item = $(item);
const a = item.find('a');
return {
title: a.attr('title'),
link: rootUrl + a.attr('href'),
};
})
.get();
const items = await Promise.all(
list.map(
async (item) =>
await ctx.cache.tryGet(item.link, async () => {
const detailResponse = await got({
method: 'get',
url: item.link,
responseType: 'buffer',
});
const content = cheerio.load(iconv.decode(detailResponse.data, 'gb2312'));
item.pubDate = new Date(content('span.time').text() + ' GMT+8').toUTCString();
item.description = content('div.content-intro').html();
return item;
})
)
);
ctx.state.data = {
title: '爱Q生活网 - 最近更新',
link: currentUrl,
item: items,
};
};