mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-11 07:40:26 +08:00
feat: add 虛詞 (#3984)
This commit is contained in:
56
lib/routes/p-articles/section.js
Normal file
56
lib/routes/p-articles/section.js
Normal file
@@ -0,0 +1,56 @@
|
||||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
const url = require('url');
|
||||
const utils = require('./utils');
|
||||
|
||||
const host = 'https://p-articles.com/';
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
let section_name = ctx.params.section;
|
||||
section_name = section_name.replace('-', '/');
|
||||
section_name += '/';
|
||||
|
||||
const link = url.resolve(host, section_name);
|
||||
|
||||
const response = await got.get(link);
|
||||
const $ = cheerio.load(response.data);
|
||||
|
||||
const top_info = {
|
||||
title: $('div.inner_top_title_01 > h1 > a').text(),
|
||||
link: url.resolve(host, $('div.inner_top_title_01 > h1 > a').attr('href')),
|
||||
};
|
||||
|
||||
const list = $('div.contect_box_04 > a')
|
||||
.map(function() {
|
||||
const info = {
|
||||
title: $(this)
|
||||
.find('h1')
|
||||
.text()
|
||||
.trim(),
|
||||
link: url.resolve(host, $(this).attr('href')),
|
||||
};
|
||||
return info;
|
||||
})
|
||||
.get();
|
||||
|
||||
list.unshift(top_info);
|
||||
|
||||
const out = await Promise.all(
|
||||
list.map(async (info) => {
|
||||
const link = info.link;
|
||||
|
||||
const cache = await ctx.cache.get(link);
|
||||
if (cache) {
|
||||
return Promise.resolve(JSON.parse(cache));
|
||||
}
|
||||
const response = await got.get(link);
|
||||
|
||||
return utils.ProcessFeed(ctx, info, response.data);
|
||||
})
|
||||
);
|
||||
ctx.state.data = {
|
||||
title: `虛詞版块-${section_name}`,
|
||||
link: link,
|
||||
item: out,
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user