Files
RSSHub/lib/routes/acwifi/index.js
T
2020-04-13 19:35:14 +08:00

49 lines
1.4 KiB
JavaScript

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 };
};