From 4014732fa7dce541a66497ad3ec13665f6c370f4 Mon Sep 17 00:00:00 2001 From: cnk Date: Mon, 10 Feb 2025 22:53:46 +0800 Subject: [PATCH] feat(routes/weibo): add showBloggerIcons option (#18302) * feat(routes/weibo): add showBloggerIcons option * fix(routes/weibo): apply review suggestion --- lib/routes/weibo/friends.ts | 2 +- lib/routes/weibo/group.ts | 2 +- lib/routes/weibo/namespace.ts | 1 + lib/routes/weibo/timeline.ts | 4 +++- lib/routes/weibo/user-bookmarks.ts | 2 +- lib/routes/weibo/user.ts | 4 +++- lib/routes/weibo/utils.ts | 14 +++++++++++--- 7 files changed, 21 insertions(+), 8 deletions(-) diff --git a/lib/routes/weibo/friends.ts b/lib/routes/weibo/friends.ts index 16b72ba2a7..119615649f 100644 --- a/lib/routes/weibo/friends.ts +++ b/lib/routes/weibo/friends.ts @@ -141,7 +141,7 @@ async function handler(ctx) { } if (displayComments === '1') { - description = await weiboUtils.formatComments(ctx, description, item); + description = await weiboUtils.formatComments(ctx, description, item, '0'); } if (displayArticle === '1') { diff --git a/lib/routes/weibo/group.ts b/lib/routes/weibo/group.ts index 6cca099d77..cfbd988fb1 100644 --- a/lib/routes/weibo/group.ts +++ b/lib/routes/weibo/group.ts @@ -96,7 +96,7 @@ async function handler(ctx) { } if (displayComments === '1') { - description = await weiboUtils.formatComments(ctx, description, item); + description = await weiboUtils.formatComments(ctx, description, item, '0'); } if (displayArticle === '1') { diff --git a/lib/routes/weibo/namespace.ts b/lib/routes/weibo/namespace.ts index e3ff1610de..f1d07f3870 100644 --- a/lib/routes/weibo/namespace.ts +++ b/lib/routes/weibo/namespace.ts @@ -31,6 +31,7 @@ export const namespace: Namespace = { | showLinkIconInDescription | 是否展示正文中的链接图标 | 0/1/true/false | true | | preferMobileLink | 是否使用移动版链接(默认使用 PC 版) | 0/1/true/false | false | | showRetweeted | 是否显示转发的微博 | 0/1/true/false | true | +| showBloggerIcons | 是否显示评论中博主的标志,只在显示热门评论时有效 | 0/1/true/false | false | 指定更多与默认值不同的参数选项可以改善 RSS 的可读性,如 diff --git a/lib/routes/weibo/timeline.ts b/lib/routes/weibo/timeline.ts index 5a3cc1a243..5303bc23af 100644 --- a/lib/routes/weibo/timeline.ts +++ b/lib/routes/weibo/timeline.ts @@ -47,6 +47,7 @@ async function handler(ctx) { let displayVideo = '1'; let displayArticle = '0'; let displayComments = '0'; + let showBloggerIcons = '0'; if (routeParams) { if (routeParams === '1' || routeParams === '0') { displayVideo = routeParams; @@ -55,6 +56,7 @@ async function handler(ctx) { 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'; + showBloggerIcons = fallback(undefined, queryToBoolean(routeParams.showBloggerIcons), false) ? '1' : '0'; } } @@ -133,7 +135,7 @@ async function handler(ctx) { // 评论的处理 if (displayComments === '1') { - description = await weiboUtils.formatComments(ctx, description, item); + description = await weiboUtils.formatComments(ctx, description, item, showBloggerIcons); } // 文章的处理 diff --git a/lib/routes/weibo/user-bookmarks.ts b/lib/routes/weibo/user-bookmarks.ts index 94f10840b7..8ce63c4b63 100644 --- a/lib/routes/weibo/user-bookmarks.ts +++ b/lib/routes/weibo/user-bookmarks.ts @@ -167,7 +167,7 @@ async function handler(ctx) { // 评论的处理 if (displayComments === '1') { - description = await weiboUtils.formatComments(ctx, description, item.mblog); + description = await weiboUtils.formatComments(ctx, description, item.mblog, '0'); } // 文章的处理 diff --git a/lib/routes/weibo/user.ts b/lib/routes/weibo/user.ts index 023aef2e87..0c4ad18976 100644 --- a/lib/routes/weibo/user.ts +++ b/lib/routes/weibo/user.ts @@ -56,6 +56,7 @@ async function handler(ctx) { let displayArticle = '0'; let displayComments = '0'; let showRetweeted = '1'; + let showBloggerIcons = '0'; if (ctx.req.param('routeParams')) { if (ctx.req.param('routeParams') === '1' || ctx.req.param('routeParams') === '0') { displayVideo = ctx.req.param('routeParams'); @@ -65,6 +66,7 @@ async function handler(ctx) { displayArticle = fallback(undefined, queryToBoolean(routeParams.displayArticle), false) ? '1' : '0'; displayComments = fallback(undefined, queryToBoolean(routeParams.displayComments), false) ? '1' : '0'; showRetweeted = fallback(undefined, queryToBoolean(routeParams.showRetweeted), false) ? '1' : '0'; + showBloggerIcons = fallback(undefined, queryToBoolean(routeParams.showBloggerIcons), false) ? '1' : '0'; } } const containerData = await cache.tryGet( @@ -161,7 +163,7 @@ async function handler(ctx) { // 评论的处理 if (displayComments === '1') { - description = await weiboUtils.formatComments(ctx, description, item.mblog); + description = await weiboUtils.formatComments(ctx, description, item.mblog, showBloggerIcons); } // 文章的处理 diff --git a/lib/routes/weibo/utils.ts b/lib/routes/weibo/utils.ts index 729150d827..9de9514dbd 100644 --- a/lib/routes/weibo/utils.ts +++ b/lib/routes/weibo/utils.ts @@ -399,7 +399,7 @@ const weiboUtils = { } return itemDesc; }, - formatComments: async (ctx, itemDesc, status) => { + formatComments: async (ctx, itemDesc, status, showBloggerIcons) => { if (status && status.comments_count && status.id && status.mid) { const id = status.id; const mid = status.mid; @@ -421,7 +421,11 @@ const weiboUtils = { itemDesc += '

热门评论

'; for (const comment of comments) { itemDesc += '

'; - itemDesc += `${comment.user.screen_name}: ${comment.text}`; + let name = comment.user.screen_name; + if (showBloggerIcons === '1' && comment.blogger_icons) { + name += comment.blogger_icons[0].name; + } + itemDesc += `${name}: ${comment.text}`; // 带有图片的评论直接输出图片 if ('pic' in comment) { itemDesc += `
`; @@ -445,7 +449,11 @@ const weiboUtils = { } } itemDesc += '

'; - itemDesc += `${com.user.screen_name}: ${com.text}`; + let name = com.user.screen_name; + if (showBloggerIcons === '1' && com.blogger_icons) { + name += com.blogger_icons[0].name; + } + itemDesc += `${name}: ${com.text}`; itemDesc += '
'; } itemDesc += '';