Skip to content

Commit 1de2457

Browse files
authored
fix(route): wxkol link (#12799)
* fix(route): wxkol link * fix(core): fix wechat-mp date parsing `var ct = "timestamp"` can appear after `var ct=function()`
1 parent cb7ea44 commit 1de2457

File tree

2 files changed

+6
-35
lines changed

2 files changed

+6
-35
lines changed

lib/utils/wechat-mp.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ const fetchArticle = (ctx, url, bypassHostCheck = false) => {
213213
}
214214

215215
let pubDate;
216-
const publish_time_script = $('script[nonce][type="text/javascript"]:contains("var ct")').first().html();
216+
const publish_time_script = $('script[nonce][type="text/javascript"]:contains("var ct")').text();
217217
const publish_time_match = publish_time_script && publish_time_script.match(/var ct *= *"?(\d{10})"?/);
218218
const publish_timestamp = publish_time_match && publish_time_match[1];
219219
if (publish_timestamp) {

lib/v2/wxkol/show.js

Lines changed: 5 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,13 @@
11
const got = require('@/utils/got');
22
const cheerio = require('cheerio');
3-
const { fetchArticle } = require('@/utils/wechat-mp');
3+
const { finishArticleItem } = require('@/utils/wechat-mp');
44
const config = require('@/config').value;
5-
const asyncPool = require('tiny-async-pool');
65

76
module.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(/url\('(.+)'\)/)[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

Comments
 (0)