feat(routes/weibo): add showBloggerIcons option (#18302)

* feat(routes/weibo): add showBloggerIcons option

* fix(routes/weibo): apply review suggestion
This commit is contained in:
cnk 2025-02-10 22:53:46 +08:00 committed by GitHub
parent a20a7e897a
commit 4014732fa7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 21 additions and 8 deletions

View File

@ -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') {

View File

@ -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') {

View File

@ -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

View File

@ -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);
}
// 文章的处理

View File

@ -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');
}
// 文章的处理

View File

@ -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);
}
// 文章的处理

View File

@ -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 += '<h3>热门评论</h3>';
for (const comment of comments) {
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}`;
let name = comment.user.screen_name;
if (showBloggerIcons === '1' && comment.blogger_icons) {
name += comment.blogger_icons[0].name;
}
itemDesc += `<a href="https://weibo.com/${comment.user.id}" target="_blank">${name}</a>: ${comment.text}`;
// 带有图片的评论直接输出图片
if ('pic' in comment) {
itemDesc += `<br><img src="${comment.pic.url}">`;
@ -445,7 +449,11 @@ const weiboUtils = {
}
}
itemDesc += '<div style="font-size: 0.9em">';
itemDesc += `<a href="https://weibo.com/${com.user.id}" target="_blank">${com.user.screen_name}</a>: ${com.text}`;
let name = com.user.screen_name;
if (showBloggerIcons === '1' && com.blogger_icons) {
name += com.blogger_icons[0].name;
}
itemDesc += `<a href="https://weibo.com/${com.user.id}" target="_blank">${name}</a>: ${com.text}`;
itemDesc += '</div>';
}
itemDesc += '</blockquote>';