Skip to content

Commit

Permalink
fix(route)(weibo): misc icons break some readers (DIYgod#9458)
Browse files Browse the repository at this point in the history
Signed-off-by: Rongrong <[email protected]>
  • Loading branch information
Rongronggg9 authored and RikkaBlue committed Apr 9, 2022
1 parent f2f9063 commit 50f08d0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
3 changes: 2 additions & 1 deletion docs/social-media.md
Original file line number Diff line number Diff line change
Expand Up @@ -1197,7 +1197,8 @@ rule
| displayVideo | 是否直接显示微博视频和 Live Photo,只在博主或个人时间线 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 |
| showEmojiInDescription | 是否展示正文中的微博表情,关闭则替换为 `[表情名]` | 0/1/true/false | true |
| showLinkIconInDescription | 是否展示正文中的链接图标 | 0/1/true/false | true |

指定更多与默认值不同的参数选项可以改善 RSS 的可读性,如

Expand Down
12 changes: 9 additions & 3 deletions lib/routes/weibo/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const weiboUtils = {
heightOfPics: fallback(params.heightOfPics, queryToInteger(routeParams.heightOfPics), -1),
sizeOfAuthorAvatar: fallback(params.sizeOfAuthorAvatar, queryToInteger(routeParams.sizeOfAuthorAvatar), 48),
showEmojiInDescription: fallback(params.showEmojiInDescription, queryToInteger(routeParams.showEmojiInDescription), true),
showLinkIconInDescription: fallback(params.showLinkIconInDescription, queryToInteger(routeParams.showLinkIconInDescription), true),
};

params = mergedParams;
Expand All @@ -44,6 +45,7 @@ const weiboUtils = {
heightOfPics,
sizeOfAuthorAvatar,
showEmojiInDescription,
showLinkIconInDescription,
} = params;

let retweeted = '';
Expand All @@ -53,10 +55,14 @@ const weiboUtils = {
if (!showEmojiInDescription) {
htmlNewLineUnreplaced = htmlNewLineUnreplaced.replace(/<span class=["']url-icon["']><img\s[^>]*?alt=["']?([^>]+?)["']?\s[^>]*?\/><\/span>/g, '$1');
}
// 去掉外部链接的图标,保留 a 标签链接 // 不能去掉,否则像超话这样的有意义的图标也会被去掉
// htmlNewLineUnreplaced = htmlNewLineUnreplaced.replace(/(<a\s[^>]*>)<span class=["']url-icon["']><img\s[^>]*><\/span>[^<>]*?<span class="surl-text">([^<>]*?)<\/span><\/a>/g, '$1$2</a>');
// 去掉乱七八糟的图标 // 不能去掉,否则像超话这样的有意义的图标也会被去掉
// 去掉链接的图标,保留 a 标签链接
if (!showLinkIconInDescription) {
htmlNewLineUnreplaced = htmlNewLineUnreplaced.replace(/(<a\s[^>]*>)<span class=["']url-icon["']><img\s[^>]*><\/span>[^<>]*?<span class="surl-text">([^<>]*?)<\/span><\/a>/g, '$1$2</a>');
}
// 去掉乱七八糟的图标 // 不需要,上述的替换应该已经把所有的图标都替换掉了,且这条 regex 会破坏上述替换不发生时的输出
// htmlNewLineUnreplaced = htmlNewLineUnreplaced.replace(/<span class=["']url-icon["']>(<img\s[^>]*?>)<\/span>/g, '');
// 将行内图标的高度设置为一行,改善阅读体验。但有些阅读器删除了 style 属性,无法生效 // 不需要,微博已经作此设置
// htmlNewLineUnreplaced = htmlNewLineUnreplaced.replace(/(?<=<span class=["']url-icon["']>)<img/g, '<img style="height: 1em"');
// 去掉全文
htmlNewLineUnreplaced = htmlNewLineUnreplaced.replace(/<br>/g, '<br>');
htmlNewLineUnreplaced = htmlNewLineUnreplaced.replace(/<a href="(.*?)"><\/a>/g, '');
Expand Down

0 comments on commit 50f08d0

Please sign in to comment.