11const got = require ( '@/utils/got' ) ;
22const cheerio = require ( 'cheerio' ) ;
3- const { fetchArticle } = require ( '@/utils/wechat-mp' ) ;
3+ const { finishArticleItem } = require ( '@/utils/wechat-mp' ) ;
44const config = require ( '@/config' ) . value ;
5- const asyncPool = require ( 'tiny-async-pool' ) ;
65
76module . exports = async ( ctx ) => {
87 const baseUrl = 'https://www.wxkol.com' ;
98 const { id } = ctx . params ;
109 const url = `${ baseUrl } /show/${ id } .html` ;
1110
12- const asyncPoolAll = async ( ...args ) => {
13- const results = [ ] ;
14- for await ( const result of asyncPool ( ...args ) ) {
15- results . push ( result ) ;
16- }
17- return results ;
18- } ;
19-
2011 const feedData = await ctx . cache . tryGet (
2112 url ,
2213 async ( ) => {
@@ -30,13 +21,13 @@ module.exports = async (ctx) => {
3021 const a = item . find ( '.title a' ) ;
3122 return {
3223 title : a . attr ( 'title' ) ,
33- link : ` ${ baseUrl } ${ a . attr ( 'href' ) } ` ,
24+ link : a . attr ( 'href' ) ,
3425 } ;
3526 } ) ;
3627
3728 return {
3829 feedTitle : $ ( 'head title' ) . text ( ) ,
39- feedDescription : $ ( 'head description' ) . text ( ) ,
30+ feedDescription : $ ( '.info_left . description i ' ) . text ( ) ,
4031 feedImage : $ ( '.main .logo .avatar' )
4132 . attr ( 'style' )
4233 . match ( / u r l \( ' ( .+ ) ' \) / ) [ 1 ] ,
@@ -47,34 +38,14 @@ module.exports = async (ctx) => {
4738 false
4839 ) ;
4940
50- const urlList = await asyncPoolAll ( 2 , feedData . feedItem , ( item ) =>
51- ctx . cache . tryGet ( item . link , async ( ) => {
52- const { data : response } = await got ( item . link ) ;
53- const $ = cheerio . load ( response ) ;
54- item . link = `${ baseUrl } ${ $ ( '.source a' ) . attr ( 'href' ) } ` ;
55- return item ;
56- } )
57- ) ;
58-
59- const items = await asyncPoolAll ( 4 , urlList , async ( item ) => {
60- const { title, author, description, summary, pubDate, mpName, link : itemLink } = await fetchArticle ( ctx , item . link , true ) ;
61-
62- item . title = title ;
63- item . author = author ;
64- item . description = description ;
65- item . summary = summary ;
66- item . pubDate = pubDate ;
67- item . author = mpName ;
68- item . link = itemLink ;
69-
70- return item ;
71- } ) ;
41+ const items = await Promise . all ( feedData . feedItem . map ( ( item ) => finishArticleItem ( ctx , item ) ) ) ;
7242
7343 ctx . state . data = {
7444 title : feedData . feedTitle ,
7545 description : feedData . feedDescription ,
7646 link : url ,
7747 image : feedData . feedImage ,
48+ icon : feedData . feedImage ,
7849 item : items ,
7950 } ;
8051} ;
0 commit comments