From 61d756a6f961063de02c1e96973da18a9044efe3 Mon Sep 17 00:00:00 2001 From: cc789461 <62095874+cc789461@users.noreply.github.com> Date: Mon, 13 Apr 2020 19:35:14 +0800 Subject: [PATCH] feat: add acwifi (#4408) --- docs/other.md | 5 ++++ lib/router.js | 3 +++ lib/routes/acwifi/index.js | 48 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+) create mode 100644 lib/routes/acwifi/index.js diff --git a/docs/other.md b/docs/other.md index 4dfb249c5..90ed2cbb3 100644 --- a/docs/other.md +++ b/docs/other.md @@ -4,6 +4,11 @@ pageClass: routes # 其他 +## acwifi 路由器交流 + +### 新闻 + + ## Apple ### 更换和维修扩展计划 diff --git a/lib/router.js b/lib/router.js index 6a015abf9..8c6df50a0 100644 --- a/lib/router.js +++ b/lib/router.js @@ -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; diff --git a/lib/routes/acwifi/index.js b/lib/routes/acwifi/index.js new file mode 100644 index 000000000..728b9b0e0 --- /dev/null +++ b/lib/routes/acwifi/index.js @@ -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 }; +};