feat(route): 微博路由 新增 category 字段 (#15734)

This commit is contained in:
CaoMeiYouRen 2024-05-28 00:40:55 +08:00 committed by GitHub
parent 3a512a3500
commit 2b5f4d092a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 5 additions and 1 deletions

View File

@ -74,6 +74,10 @@ const weiboUtils = {
if (!showLinkIconInDescription) {
htmlNewLineUnreplaced = htmlNewLineUnreplaced.replaceAll(/(<a\s[^>]*>)<span class=["']?url-icon["']?><img\s[^>]*><\/span>[^<>]*?<span class=["']?surl-text["']?>([^<>]*?)<\/span><\/a>/g, '$1$2</a>');
}
// 提取 话题作为 category
const category: string[] = htmlNewLineUnreplaced.match(/<span class=["']?surl-text["']?>#([^<>]*?)#<\/span>/g)?.map((e) => e?.match(/#([^#]+)#/)?.[1]);
// 去掉乱七八糟的图标 // 不需要,上述的替换应该已经把所有的图标都替换掉了,且这条 regex 会破坏上述替换不发生时的输出
// htmlNewLineUnreplaced = htmlNewLineUnreplaced.replace(/<span class=["']?url-icon["']?>(<img\s[^>]*?>)<\/span>/g, '');
// 将行内图标的高度设置为一行,改善阅读体验。但有些阅读器删除了 style 属性,无法生效 // 不需要,微博已经作此设置
@ -241,7 +245,7 @@ const weiboUtils = {
const author = status.user?.screen_name;
const pubDate = status.created_at;
return { description: html, title, link, guid, author, pubDate };
return { description: html, title, link, guid, author, pubDate, category };
},
getShowData: async (uid, bid) => {
const link = `https://m.weibo.cn/statuses/show?id=${bid}`;