feat(twitter): add option to number the medias (#19050)

* feat(twitter): add number to the media

* (feat/twitter): add option `mediaNumber` to number the medias in tweets

--------
This commit is contained in:
Unknown 2025-06-06 01:08:59 +08:00 committed by GitHub
parent d929c7a15c
commit c150211749
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 1 deletions

View File

@ -29,6 +29,7 @@ export const namespace: Namespace = {
| \`forceWebApi\` | Force using Web API even if Developer API is configured, only available in \`/twitter/user\` and \`/twitter/keyword\` | \`0\`/\`1\`/\`true\`/\`false\` | \`false\` |
| \`count\` | \`count\` parameter passed to Twitter API, only available in \`/twitter/user\` | Unspecified/Integer | Unspecified |
| \`onlyMedia\` | Only get tweets with a media | \`0\`/\`1\`/\`true\`/\`false\` | \`false\` |
| \`mediaNumber \` | Number the medias | \`0\`/\`1\`/\`true\`/\`false\` | \`false\` |
Specify different option values than default values to improve readability. The URL

View File

@ -67,6 +67,7 @@ const ProcessFeed = (ctx, { data = [] }, params = {}) => {
heightOfPics: fallback(params.heightOfPics, queryToInteger(routeParams.get('heightOfPics')), -1),
sizeOfAuthorAvatar: fallback(params.sizeOfAuthorAvatar, queryToInteger(routeParams.get('sizeOfAuthorAvatar')), 48),
sizeOfQuotedAuthorAvatar: fallback(params.sizeOfQuotedAuthorAvatar, queryToInteger(routeParams.get('sizeOfQuotedAuthorAvatar')), 24),
mediaNumber: fallback(params.mediaNumber, queryToInteger(routeParams.get('mediaNumber')), false),
};
params = mergedParams;
@ -85,7 +86,7 @@ const ProcessFeed = (ctx, { data = [] }, params = {}) => {
addLinkForPics,
showTimestampInDescription,
showQuotedInTitle,
mediaNumber,
widthOfPics,
heightOfPics,
sizeOfAuthorAvatar,
@ -116,6 +117,8 @@ const ProcessFeed = (ctx, { data = [] }, params = {}) => {
const formatMedia = (item) => {
let img = '';
if (item.extended_entities) {
const mediaCount = item.extended_entities.media.length;
let index = 1;
for (const media of item.extended_entities.media) {
// https://developer.x.com/en/docs/tweets/data-dictionary/overview/extended-entities-object
let content = '';
@ -156,6 +159,11 @@ const ProcessFeed = (ctx, { data = [] }, params = {}) => {
}
img += content;
if (mediaNumber) {
img += `<p style="text-align:center">${index}/${mediaCount}</p>`;
index++;
}
}
}