mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-03 18:48:12 +08:00
42 lines
1.1 KiB
JavaScript
42 lines
1.1 KiB
JavaScript
// Warning: The author still knows nothing about javascript!
|
|
|
|
// params:
|
|
// type: subject type
|
|
|
|
const got = require('@/utils/got'); // get web content
|
|
const cheerio = require('cheerio'); // html parser
|
|
const get_article = require('./_article');
|
|
const { isValidHost } = require('@/utils/valid-host');
|
|
|
|
module.exports = async (ctx) => {
|
|
const type = ctx.params.type ?? 'www';
|
|
if (!isValidHost(type)) {
|
|
throw Error('Invalid type');
|
|
}
|
|
|
|
const base_url = `https://${type}.solidot.org`;
|
|
const response = await got({
|
|
method: 'get',
|
|
url: base_url,
|
|
});
|
|
const data = response.data; // content is html format
|
|
const $ = cheerio.load(data);
|
|
|
|
// get urls
|
|
const a = $('div.block_m').find('div.bg_htit > h2 > a');
|
|
const urls = [];
|
|
for (let i = 0; i < a.length; ++i) {
|
|
urls.push($(a[i]).attr('href'));
|
|
}
|
|
|
|
// get articles
|
|
const msg_list = await Promise.all(urls.map((u) => ctx.cache.tryGet(u, () => get_article(u))));
|
|
|
|
// feed the data
|
|
ctx.state.data = {
|
|
title: '奇客的资讯,重要的东西',
|
|
link: base_url,
|
|
item: msg_list,
|
|
};
|
|
};
|