forked from DIYgod/RSSHub
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat(route): wxkol * fix: use async pool
- Loading branch information
Showing
6 changed files
with
113 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
'/show/:id': ['TonyRL'], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module.exports = { | ||
'wxkol.com': { | ||
_name: '微小领', | ||
'.': [ | ||
{ | ||
title: '微信公众号', | ||
docs: 'https://docs.rsshub.app/new-media.html#wei-xiao-ling', | ||
source: ['/show/:id'], | ||
target: (params) => `/wxkol/show/${params.id.replace('.html', '')}`, | ||
}, | ||
], | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = (router) => { | ||
router.get('/show/:id', require('./show')); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
const got = require('@/utils/got'); | ||
const cheerio = require('cheerio'); | ||
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 () => { | ||
const { data: response } = await got(url); | ||
const $ = cheerio.load(response); | ||
|
||
const list = $('.artlist li') | ||
.toArray() | ||
.map((item) => { | ||
item = $(item); | ||
const a = item.find('.title a'); | ||
return { | ||
title: a.attr('title'), | ||
link: `${baseUrl}${a.attr('href')}`, | ||
}; | ||
}); | ||
|
||
return { | ||
feedTitle: $('head title').text(), | ||
feedDescription: $('head description').text(), | ||
feedImage: $('.main .logo .avatar') | ||
.attr('style') | ||
.match(/url\('(.+)'\)/)[1], | ||
feedItem: list, | ||
}; | ||
}, | ||
config.cache.routeExpire, | ||
false | ||
); | ||
|
||
const urlList = await asyncPoolAll(2, 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(4, 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, | ||
description: feedData.feedDescription, | ||
link: url, | ||
image: feedData.feedImage, | ||
item: items, | ||
}; | ||
}; |