feat: add mobilism ebook releases (#4867)

This commit is contained in:
Ethan Shen
2020-05-28 16:21:20 +08:00
committed by GitHub
parent 389161680d
commit c95d11369f
3 changed files with 52 additions and 0 deletions

View File

@@ -10,6 +10,12 @@ pageClass: routes
<Route author="HenryQW" example="/allpoetry/newest" path="/allpoetry/:order?" :paramsDesc="['排序方式, `best``newest`, 缺省 `best`']"/> <Route author="HenryQW" example="/allpoetry/newest" path="/allpoetry/:order?" :paramsDesc="['排序方式, `best``newest`, 缺省 `best`']"/>
## Mobilism
### eBook Releases
<Route author="nczitzk" example="/mobilism/release" path="/mobilism/release" />
## UU 看书 ## UU 看书
### 小说更新 ### 小说更新

View File

@@ -2771,4 +2771,7 @@ router.get('/zhutix/latest', require('./routes/zhutix/latest'));
// arXiv // arXiv
router.get('/arxiv/:query', require('./routes/arxiv/query')); router.get('/arxiv/:query', require('./routes/arxiv/query'));
// Mobilism
router.get('/mobilism/release', require('./routes/mobilism/release'));
module.exports = router; module.exports = router;

View File

@@ -0,0 +1,43 @@
const url = require('url');
const got = require('@/utils/got');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const currentUrl = `https://forum.mobilism.org/viewforum.php?f=19`;
const response = await got({
method: 'get',
url: currentUrl,
});
const $ = cheerio.load(response.data);
const list = $('tbody')
.eq(1)
.find('tr')
.map((_, item) => {
item = $(item);
const a = item.find('a');
return {
title: a.text(),
link: url.resolve(`https://forum.mobilism.org`, a.attr('href')),
};
})
.get();
const items = await Promise.all(
list.map(
async (item) =>
await ctx.cache.tryGet(item.link, async () => {
const res = await got({ method: 'get', url: item.link });
const content = cheerio.load(res.data);
item.description = content('div.content').html();
return item;
})
)
);
ctx.state.data = {
title: 'Mobilism - eBook Releases',
link: currentUrl,
item: items,
};
};