feat: add acwifi (#4408)
This commit is contained in:
parent
8a5dbbcc1f
commit
61d756a6f9
|
|
@ -4,6 +4,11 @@ pageClass: routes
|
|||
|
||||
# 其他
|
||||
|
||||
## acwifi 路由器交流
|
||||
|
||||
### 新闻
|
||||
|
||||
<Route author="cc798461" example="/acwifi" path="/acwifi"/>
|
||||
## Apple
|
||||
|
||||
### 更换和维修扩展计划
|
||||
|
|
|
|||
|
|
@ -2514,4 +2514,7 @@ router.get('/blogs/diygod/gk', require('./routes/blogs/diygod/gk'));
|
|||
router.get('/hbut/news/:type', require('./routes/universities/hbut/news'));
|
||||
router.get('/hbut/cs/:type', require('./routes/universities/hbut/cs'));
|
||||
|
||||
// acwifi
|
||||
router.get('/acwifi', require('./routes/acwifi'));
|
||||
|
||||
module.exports = router;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,48 @@
|
|||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const baseUrl = 'https://www.acwifi.net/';
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: baseUrl,
|
||||
});
|
||||
const $ = cheerio.load(response.data);
|
||||
const list = $('div.widget.widget_recent_entries li').get();
|
||||
|
||||
const ProcessFeed = (data) => {
|
||||
const $ = cheerio.load(data);
|
||||
return {
|
||||
desc: $('article.article-content').html(),
|
||||
};
|
||||
};
|
||||
|
||||
const out = await Promise.all(
|
||||
list.map(async (item) => {
|
||||
const $ = cheerio.load(item);
|
||||
const $a = $('a');
|
||||
const link = $a.attr('href');
|
||||
|
||||
const cache = await ctx.cache.get(link);
|
||||
if (cache) {
|
||||
return Promise.resolve(JSON.parse(cache));
|
||||
}
|
||||
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: link,
|
||||
});
|
||||
const feed = ProcessFeed(response.data);
|
||||
const description = feed.desc;
|
||||
|
||||
const single = {
|
||||
title: $a.text(),
|
||||
description,
|
||||
link: link,
|
||||
};
|
||||
ctx.cache.set(link, JSON.stringify(single));
|
||||
return Promise.resolve(single);
|
||||
})
|
||||
);
|
||||
ctx.state.data = { title: '路由器交流', link: baseUrl, item: out };
|
||||
};
|
||||
Loading…
Reference in New Issue