mirror of
https://github.com/DIYgod/RSSHub.git
synced 2026-09-24 23:12:34 +08:00
feat(route)(weibo): display comments (#9394)
Signed-off-by: Rongrong <15956627+Rongronggg9@users.noreply.github.com>
This commit is contained in:
@@ -1189,6 +1189,7 @@ rule
|
||||
| sizeOfAuthorAvatar | 作者头像大小 | 数字 | 48 |
|
||||
| displayVideo | 是否直接显示微博视频,只在博主或个人时间线 RSS 中有效 | 0/1/true/false | true |
|
||||
| displayArticle | 是否直接显示微博文章,只在博主或个人时间线 RSS 中有效 | 0/1/true/false | false |
|
||||
| displayComments | 是否直接显示热门评论,只在博主或个人时间线 RSS 中有效 | 0/1/true/false | false |
|
||||
| showEmojiInDescription | 是否展示正文中的 emoji 表情 | 0/1/true/false | true |
|
||||
|
||||
指定更多与默认值不同的参数选项可以改善 RSS 的可读性,如
|
||||
|
||||
@@ -12,6 +12,7 @@ module.exports = async (ctx) => {
|
||||
const token = await ctx.cache.get('weibotimelineuid' + uid, false);
|
||||
let displayVideo = '1';
|
||||
let displayArticle = '0';
|
||||
let displayComments = '0';
|
||||
if (routeParams) {
|
||||
if (routeParams === '1' || routeParams === '0') {
|
||||
displayVideo = routeParams;
|
||||
@@ -19,6 +20,7 @@ module.exports = async (ctx) => {
|
||||
const routeParams = querystring.parse(ctx.params.routeParams);
|
||||
displayVideo = fallback(undefined, queryToBoolean(routeParams.displayVideo), true) ? '1' : '0';
|
||||
displayArticle = fallback(undefined, queryToBoolean(routeParams.displayArticle), false) ? '1' : '0';
|
||||
displayComments = fallback(undefined, queryToBoolean(routeParams.displayComments), false) ? '1' : '0';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,6 +88,11 @@ module.exports = async (ctx) => {
|
||||
}
|
||||
}
|
||||
|
||||
// 评论的处理
|
||||
if (displayComments === '1') {
|
||||
description = await weiboUtils.formatComments(ctx, description, item);
|
||||
}
|
||||
|
||||
// 文章的处理
|
||||
if (displayArticle === '1') {
|
||||
// 含被转发微博时需要从被转发微博中获取文章
|
||||
|
||||
@@ -9,6 +9,7 @@ module.exports = async (ctx) => {
|
||||
const uid = ctx.params.uid;
|
||||
let displayVideo = '1';
|
||||
let displayArticle = '0';
|
||||
let displayComments = '0';
|
||||
if (ctx.params.routeParams) {
|
||||
if (ctx.params.routeParams === '1' || ctx.params.routeParams === '0') {
|
||||
displayVideo = ctx.params.routeParams;
|
||||
@@ -16,6 +17,7 @@ module.exports = async (ctx) => {
|
||||
const routeParams = querystring.parse(ctx.params.routeParams);
|
||||
displayVideo = fallback(undefined, queryToBoolean(routeParams.displayVideo), true) ? '1' : '0';
|
||||
displayArticle = fallback(undefined, queryToBoolean(routeParams.displayArticle), false) ? '1' : '0';
|
||||
displayComments = fallback(undefined, queryToBoolean(routeParams.displayComments), false) ? '1' : '0';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,6 +109,11 @@ module.exports = async (ctx) => {
|
||||
}
|
||||
}
|
||||
|
||||
// 评论的处理
|
||||
if (displayComments === '1') {
|
||||
description = await weiboUtils.formatComments(ctx, description, item.mblog);
|
||||
}
|
||||
|
||||
// 文章的处理
|
||||
if (displayArticle === '1') {
|
||||
// 含被转发微博时需要从被转发微博中获取文章
|
||||
|
||||
@@ -348,6 +348,45 @@ const weiboUtils = {
|
||||
}
|
||||
return itemDesc;
|
||||
},
|
||||
formatComments: async (ctx, itemDesc, status) => {
|
||||
if (status && status.comments_count && status.id && status.mid) {
|
||||
const id = status.id;
|
||||
const mid = status.mid;
|
||||
const link = `https://m.weibo.cn/comments/hotflow?id=${id}&mid=${mid}&max_id_type=0`;
|
||||
const response = await ctx.cache.tryGet(link, async () => {
|
||||
const _response = await got.get(link, {
|
||||
headers: {
|
||||
Referer: `https://m.weibo.cn/detail/${id}`,
|
||||
'MWeibo-Pwa': 1,
|
||||
'X-Requested-With': 'XMLHttpRequest',
|
||||
'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1',
|
||||
},
|
||||
});
|
||||
return _response.data;
|
||||
});
|
||||
if (response.data && response.data.data) {
|
||||
const comments = response.data.data;
|
||||
itemDesc += `<br clear="both" /><div style="clear: both"></div><div style="background: #80808010;border-top:1px solid #80808030;border-bottom:1px solid #80808030;margin:0;padding:5px 20px;">`;
|
||||
itemDesc += '<h3>热门评论</h3>';
|
||||
comments.forEach((comment) => {
|
||||
itemDesc += '<p style="margin-bottom: 0.5em;margin-top: 0.5em">';
|
||||
itemDesc += `<a href="https://weibo.com/${comment.user.id}" target="_blank">${comment.user.screen_name}</a>: ${comment.text}`;
|
||||
if (comment.comments) {
|
||||
itemDesc += '<blockquote style="border-left:0.2em solid #80808080; margin-left: 0.3em; padding-left: 0.5em; margin-bottom: 0.5em; margin-top: 0.25em">';
|
||||
comment.comments.forEach((comment) => {
|
||||
itemDesc += '<div style="font-size: 0.9em">';
|
||||
itemDesc += `<a href="https://weibo.com/${comment.user.id}" target="_blank">${comment.user.screen_name}</a>: ${comment.text}`;
|
||||
itemDesc += '</div>';
|
||||
});
|
||||
itemDesc += '</blockquote>';
|
||||
}
|
||||
itemDesc += '</p>';
|
||||
});
|
||||
itemDesc += '</div>';
|
||||
}
|
||||
}
|
||||
return itemDesc;
|
||||
},
|
||||
};
|
||||
|
||||
module.exports = weiboUtils;
|
||||
|
||||
Reference in New Issue
Block a user