mirror of
https://github.com/DIYgod/RSSHub.git
synced 2026-09-01 14:57:14 +08:00
fix(route): wxkol (#12909)
This commit is contained in:
+33
-3
@@ -1,13 +1,22 @@
|
||||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
const { finishArticleItem } = require('@/utils/wechat-mp');
|
||||
const { fetchArticle } = require('@/utils/wechat-mp');
|
||||
const config = require('@/config').value;
|
||||
const asyncPool = require('tiny-async-pool');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const baseUrl = 'https://www.wxkol.com';
|
||||
const { id } = ctx.params;
|
||||
const url = `${baseUrl}/show/${id}.html`;
|
||||
|
||||
const asyncPoolAll = async (...args) => {
|
||||
const results = [];
|
||||
for await (const result of asyncPool(...args)) {
|
||||
results.push(result);
|
||||
}
|
||||
return results;
|
||||
};
|
||||
|
||||
const feedData = await ctx.cache.tryGet(
|
||||
url,
|
||||
async () => {
|
||||
@@ -21,7 +30,7 @@ module.exports = async (ctx) => {
|
||||
const a = item.find('.title a');
|
||||
return {
|
||||
title: a.attr('title'),
|
||||
link: a.attr('href'),
|
||||
link: `${baseUrl}${a.attr('href')}`,
|
||||
};
|
||||
});
|
||||
|
||||
@@ -38,7 +47,28 @@ module.exports = async (ctx) => {
|
||||
false
|
||||
);
|
||||
|
||||
const items = await Promise.all(feedData.feedItem.map((item) => finishArticleItem(ctx, item)));
|
||||
const urlList = await asyncPoolAll(5, feedData.feedItem, (item) =>
|
||||
ctx.cache.tryGet(item.link, async () => {
|
||||
const { data: response } = await got(item.link);
|
||||
const $ = cheerio.load(response);
|
||||
item.link = `${baseUrl}${$('.source a').attr('href')}`;
|
||||
return item;
|
||||
})
|
||||
);
|
||||
|
||||
const items = await asyncPoolAll(5, urlList, async (item) => {
|
||||
const { title, author, description, summary, pubDate, mpName, link: itemLink } = await fetchArticle(ctx, item.link, true);
|
||||
|
||||
item.title = title;
|
||||
item.author = author;
|
||||
item.description = description;
|
||||
item.summary = summary;
|
||||
item.pubDate = pubDate;
|
||||
item.author = mpName;
|
||||
item.link = itemLink;
|
||||
|
||||
return item;
|
||||
});
|
||||
|
||||
ctx.state.data = {
|
||||
title: feedData.feedTitle,
|
||||
|
||||
Reference in New Issue
Block a user