feat(routes/weibo): add showBloggerIcons option (#18302)
* feat(routes/weibo): add showBloggerIcons option * fix(routes/weibo): apply review suggestion
This commit is contained in:
parent
a20a7e897a
commit
4014732fa7
|
|
@ -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') {
|
||||
|
|
|
|||
|
|
@ -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') {
|
||||
|
|
|
|||
|
|
@ -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 的可读性,如
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
||||
// 文章的处理
|
||||
|
|
|
|||
|
|
@ -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');
|
||||
}
|
||||
|
||||
// 文章的处理
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
||||
// 文章的处理
|
||||
|
|
|
|||
|
|
@ -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>';
|
||||
|
|
|
|||
Loading…
Reference in New Issue