feat(route/weibo): configurable link; unified metadata (#12522)

Signed-off-by: Rongrong <i@rong.moe>
This commit is contained in:
Rongrong
2023-05-16 23:40:43 +08:00
committed by GitHub
parent d83108dda9
commit 6bfa472c23
8 changed files with 33 additions and 50 deletions
+4 -3
View File
@@ -1522,6 +1522,7 @@ rule
| displayComments | 是否直接显示热门评论,只在博主或个人时间线 RSS 中有效 | 0/1/true/false | false |
| showEmojiInDescription | 是否展示正文中的微博表情,关闭则替换为 `[表情名]` | 0/1/true/false | true |
| showLinkIconInDescription | 是否展示正文中的链接图标 | 0/1/true/false | true |
| preferMobileLink | 是否使用移动版链接(默认使用 PC 版) | 0/1/true/false | false |
指定更多与默认值不同的参数选项可以改善 RSS 的可读性,如
@@ -1541,7 +1542,7 @@ rule
### 关键词
<Route author="DIYgod" example="/weibo/keyword/DIYgod" path="/weibo/keyword/:keyword/:routeParams?" :paramsDesc="['你想订阅的微博关键词', '额外参数;请参阅上面的说明和表格']" anticrawler="1" radar="1" rssbud="1"/>
<Route author="DIYgod Rongronggg9" example="/weibo/keyword/DIYgod" path="/weibo/keyword/:keyword/:routeParams?" :paramsDesc="['你想订阅的微博关键词', '额外参数;请参阅上面的说明和表格']" anticrawler="1" radar="1" rssbud="1"/>
### 热搜榜
@@ -1549,7 +1550,7 @@ rule
### 超话
<Route author="zengxs" example="/weibo/super_index/1008084989d223732bf6f02f75ea30efad58a9/sort_time" path="/weibo/super_index/:id/:type?/:routeParams?" :paramsDesc="['超话ID', '类型:见下表', '额外参数;请参阅上面的说明和表格']" anticrawler="1" radar="1" rssbud="1"/>
<Route author="zengxs Rongronggg9" example="/weibo/super_index/1008084989d223732bf6f02f75ea30efad58a9/sort_time" path="/weibo/super_index/:id/:type?/:routeParams?" :paramsDesc="['超话ID', '类型:见下表', '额外参数;请参阅上面的说明和表格']" anticrawler="1" radar="1" rssbud="1"/>
| type | 备注 |
| --------- | ---------------- |
@@ -1576,7 +1577,7 @@ rule
### 自定义分组
<Route author="monologconnor" example="/weibo/group/4541216424989965/微博分组/:routeParams?" path="/weibo/group/:gid/:gname?/:routeParams?" :paramsDesc="['分组id, 在网页版分组地址栏末尾`?gid=`处获取', '分组显示名称; 默认为: `微博分组`', '额外参数;请参阅上面的说明和表格']" anticrawler="1" selfhost="1">
<Route author="monologconnor Rongronggg9" example="/weibo/group/4541216424989965/微博分组/:routeParams?" path="/weibo/group/:gid/:gname?/:routeParams?" :paramsDesc="['分组id, 在网页版分组地址栏末尾`?gid=`处获取', '分组显示名称; 默认为: `微博分组`', '额外参数;请参阅上面的说明和表格']" anticrawler="1" selfhost="1">
::: warning 注意
+1 -7
View File
@@ -54,11 +54,8 @@ module.exports = async (ctx) => {
}
}
const link = `https://m.weibo.cn/status/${item.bid}`;
const formatExtended = weiboUtils.formatExtended(ctx, item);
let description = formatExtended.description;
const title = formatExtended.title;
const pubDate = item.created_at;
if (displayVideo === '1') {
if (item.retweeted_status) {
@@ -81,11 +78,8 @@ module.exports = async (ctx) => {
}
return {
title,
...formatExtended,
description,
link,
pubDate,
author: item.user.screen_name,
};
})
);
+1 -10
View File
@@ -37,19 +37,10 @@ module.exports = async (ctx) => {
if (item.mblog.retweeted_status && item.mblog.retweeted_status.created_at) {
item.mblog.retweeted_status.created_at = timezone(item.mblog.retweeted_status.created_at, +8);
}
const formatExtended = weiboUtils.formatExtended(ctx, item.mblog, {
return weiboUtils.formatExtended(ctx, item.mblog, undefined, {
showAuthorInTitle: fallback(undefined, queryToBoolean(routeParams.showAuthorInTitle), true),
showAuthorInDesc: fallback(undefined, queryToBoolean(routeParams.showAuthorInDesc), true),
});
const title = formatExtended.title;
const description = formatExtended.description;
return {
title,
description,
pubDate: item.mblog.created_at,
author: item.mblog.user.screen_name,
link: `https://weibo.com/${item.mblog.user.id}/${item.mblog.bid}`,
};
}),
});
};
+4 -4
View File
@@ -1,9 +1,9 @@
module.exports = {
'/group/:gid/:gname?/:routeParams?': ['monologconnor'],
'/keyword/:keyword/:routeParams?': ['DIYgod'],
'/group/:gid/:gname?/:routeParams?': ['monologconnor', 'Rongronggg9'],
'/keyword/:keyword/:routeParams?': ['DIYgod', 'Rongronggg9'],
'/oasis/user/:userid': ['kt286'],
'/search/hot': ['xyqfer'],
'/super_index/:id/:type?/:routeParams?': ['zengxs'],
'/timeline/:uid/:feature?/:routeParams?': ['zytomorrow', 'DIYgod ', 'Rongronggg9'],
'/super_index/:id/:type?/:routeParams?': ['zengxs', 'Rongronggg9'],
'/timeline/:uid/:feature?/:routeParams?': ['zytomorrow', 'DIYgod', 'Rongronggg9'],
'/user/:uid/:routeParams?': ['DIYgod', 'iplusx', 'Rongronggg9'],
};
+1 -10
View File
@@ -1,6 +1,5 @@
const got = require('@/utils/got');
const weiboUtils = require('./utils');
const timezone = require('@/utils/timezone');
const queryString = require('query-string');
const config = require('@/config').value;
@@ -40,15 +39,7 @@ module.exports = async (ctx) => {
if (mblogCard.card_type === '9' && 'mblog' in mblogCard) {
const mblog = mblogCard.mblog;
const formatExtended = weiboUtils.formatExtended(ctx, mblog);
const title = formatExtended.title;
const desc = formatExtended.description;
resultItems.push({
title,
description: desc,
author: mblog.user.screen_name,
link: `https://weibo.com/${mblog.user.id}/${mblog.bid}`,
pubDate: timezone(mblog.created_at, +8),
});
resultItems.push(formatExtended);
}
}
}
+5 -5
View File
@@ -83,11 +83,11 @@ module.exports = async (ctx) => {
}
}
const link = `https://weibo.com/${uid}/${item.id}`;
const guid = `https://weibo.com/${uid}/${item.id}`;
// not using formatExtended.guid in order not to introduce breaking change
const formatExtended = weiboUtils.formatExtended(ctx, item);
const formatExtended = weiboUtils.formatExtended(ctx, item, uid);
let description = formatExtended.description;
const title = formatExtended.title;
const pubDate = isDataOK ? parseDate(data.created_at) : parseDate(item.created_at);
// 视频的处理
@@ -116,9 +116,9 @@ module.exports = async (ctx) => {
}
return {
title,
...formatExtended,
guid,
description,
link,
pubDate,
author: item.user.screen_name,
};
+2 -8
View File
@@ -94,11 +94,8 @@ module.exports = async (ctx) => {
}
}
const link = `https://m.weibo.cn/status/${item.mblog.bid}`;
const formatExtended = weiboUtils.formatExtended(ctx, item.mblog);
const formatExtended = weiboUtils.formatExtended(ctx, item.mblog, uid);
let description = formatExtended.description;
const title = formatExtended.title;
const pubDate = item.mblog.created_at;
// 视频的处理
if (displayVideo === '1') {
@@ -126,11 +123,8 @@ module.exports = async (ctx) => {
}
return {
title,
...formatExtended,
description,
link,
pubDate,
author: item.mblog.user.screen_name,
isPinned: item.profile_type_id?.startsWith('proweibotop'),
};
})
+15 -3
View File
@@ -14,7 +14,9 @@ const weiboUtils = {
.replace(/<[^<]*>/g, '')
.replace(/\n/g, ' ')
.trim(),
formatExtended: (ctx, status, params = {}, picsPrefixes = []) => {
formatExtended: (ctx, status, uid = undefined, params = {}, picsPrefixes = []) => {
// `uid = undefined` to explicitly mark it as optional, avoiding IDEs prompting warnings
// undefined and strings like "1" is also safely parsed, so no if branch is needed
const routeParams = querystring.parse(ctx.params.routeParams);
@@ -35,6 +37,7 @@ const weiboUtils = {
sizeOfAuthorAvatar: fallback(params.sizeOfAuthorAvatar, queryToInteger(routeParams.sizeOfAuthorAvatar), 48),
showEmojiInDescription: fallback(params.showEmojiInDescription, queryToInteger(routeParams.showEmojiInDescription), true),
showLinkIconInDescription: fallback(params.showLinkIconInDescription, queryToInteger(routeParams.showLinkIconInDescription), true),
preferMobileLink: fallback(params.preferMobileLink, queryToBoolean(routeParams.preferMobileLink), false),
};
params = mergedParams;
@@ -56,6 +59,7 @@ const weiboUtils = {
sizeOfAuthorAvatar,
showEmojiInDescription,
showLinkIconInDescription,
preferMobileLink,
} = params;
let retweeted = '';
@@ -191,7 +195,7 @@ const weiboUtils = {
retweetedParams.showAuthorInDesc = true;
retweetedParams.showAuthorAvatarInDesc = false;
retweetedParams.showAtBeforeAuthor = true;
retweeted += weiboUtils.formatExtended(ctx, status.retweeted_status, retweetedParams, picsPrefixes).description;
retweeted += weiboUtils.formatExtended(ctx, status.retweeted_status, undefined, retweetedParams, picsPrefixes).description;
html += retweeted;
@@ -231,7 +235,15 @@ const weiboUtils = {
title += ' [视频]';
}
return { description: html, title };
uid = uid || status.user?.id;
const bid = status.bid || status.id;
const guid = uid ? `https://weibo.com/${uid}/${bid}` : `https://m.weibo.cn/status/${bid}`;
const link = preferMobileLink ? `https://m.weibo.cn/status/${bid}` : guid;
const author = status.user?.screen_name;
const pubDate = status.created_at;
return { description: html, title, link, guid, author, pubDate };
},
getShowData: async (uid, bid) => {
const link = `https://m.weibo.cn/statuses/show?id=${bid}`;