diff --git a/lib/routes/douban/people/status.js b/lib/routes/douban/people/status.js
index a0f181a87..4f6c1173f 100644
--- a/lib/routes/douban/people/status.js
+++ b/lib/routes/douban/people/status.js
@@ -1,125 +1,56 @@
const got = require('@/utils/got');
-function getContentByActivity(item, isRenderingRepost = false) {
- const { status, comments } = item;
+function getContentByActivity(status) {
let description = '';
let title = '';
+ switch (status.activity) {
+ case '说':
+ title = `${status.author.name} ${status.activity}:${status.text}`;
+ description = status.text;
+ status.images.forEach((image) => {
+ description += `

`;
+ });
+ break;
+ case '转发':
+ description = `${status.text}
`;
+ if (status.reshared_status.deleted) {
+ title = `${status.author.name} ${status.activity} 广播:原动态已被发布者删除`;
+ description += `原动态已被发布者删除`;
+ } else {
+ description += getContentByActivity(status.reshared_status).title;
+ title = `${status.author.name} ${status.activity} ${status.reshared_status.author.name} 的广播:${status.reshared_status.text}`;
+ status.reshared_status.images.forEach((image) => {
+ description += `
`;
+ });
+ }
- let usernameAndAvatar = ``;
- if (!isRenderingRepost) {
- usernameAndAvatar += `
`;
+ break;
+ default:
+ description = `${status.text ? `${status.text}
` : ''}`;
+ title = `${status.author.name}${status.activity}: ${description}`;
+ if (status.card) {
+ let image;
+ if (status.card.image && (status.card.image.large || status.card.image.normal)) {
+ image = (status.card.image.large || status.card.image.normal).url;
+ }
+ if (status.card.rating) {
+ description += `豆瓣评分:${status.card.rating}
${status.card.subtitle}${image ? `
` : ''}
《${status.card.title}》`;
+ title = `${status.author.name}${status.activity}:《${status.card.title}》`;
+ } else {
+ description += `${status.card.subtitle}${image ? `
` : ''}
${status.card.url ? `${status.card.title}` : ''}`;
+ title = `${status.author.name} ${status.activity}:「${status.card.title}」${status.text}`;
+ }
+ }
+ if (status.video_card) {
+ const videoCover = status.video_card.video_info && status.video_card.video_info.cover_url;
+ const videoSrc = status.video_card.video_info && status.video_card.video_info.video_url;
+ description += `${videoSrc ? `
` : ''}
${
+ status.video_card.title ? `${status.video_card.title}` : ''
+ }`;
+ title = `${status.author.name}${status.activity}:《${status.video_card.title}》`;
+ }
+ break;
}
- usernameAndAvatar += `${status.author.name} `;
-
- title += `${status.author.name} ${status.activity}: `;
- description += usernameAndAvatar + `${status.activity}`;
-
- description += `
${status.create_time}
`;
-
- let text = status.text;
- let lastIndex = 0;
- const replacedTextSegements = [];
- for (const entity of status.entities) {
- replacedTextSegements.push(text.slice(lastIndex, entity.start));
- replacedTextSegements.push(`${entity.title}`);
- lastIndex = entity.end;
- }
- replacedTextSegements.push(text.slice(lastIndex));
- text = replacedTextSegements.join('');
-
- // text // images // video_info // parent status
-
- description += text;
-
- if (status.card) {
- if (status.card.rating) {
- title += `《${status.card.title}》`;
- } else {
- title += `「${status.card.title}」`;
- }
- }
-
- title += status.text.replace('\n', '');
-
- if (status.images.length) {
- description += `
`;
- status.images.forEach((image) => {
- description += '
';
- });
- }
-
- if (status.video_info) {
- description += `
`;
- const videoCover = status.video_info.cover_url;
- const videoSrc = status.video_info.video_url;
- description += `${videoSrc ? `` : ''}`;
- }
-
- if (status.parent_status) {
- description += ' 🔁 ';
- title += ' 🔁 ';
-
- let usernameAndAvatar = ``;
- usernameAndAvatar += `${status.parent_status.author.name}: `;
- description += usernameAndAvatar + status.parent_status.text;
- title += usernameAndAvatar + status.parent_status.text;
- }
-
- // card
- if (status.card) {
- let image;
- if (status.card.image && (status.card.image.large || status.card.image.normal)) {
- image = status.card.image.large || status.card.image.normal;
- }
-
- description += `
`;
- if (image) {
- description += `
`;
- }
- description += `${status.card.title}
${status.card.subtitle}`;
- if (status.card.rating) {
- description += `
评分:${status.card.rating}`;
- }
- description += `
`;
- }
-
- // video_card
- if (status.video_card) {
- description += `
`;
- const videoCover = status.video_card.video_info && status.video_card.video_info.cover_url;
- const videoSrc = status.video_card.video_info && status.video_card.video_info.video_url;
- description += `${videoSrc ? `` : ''}
${status.video_card.title ? `${status.video_card.title}` : ''}`;
- description += `
`;
- }
-
- // reshared_status
- if (status.reshared_status) {
- description += `
`;
-
- if (status.reshared_status.deleted) {
- description += `原动态已被发布者删除`;
- title += ` | 原动态已被发布者删除`;
- } else {
- description += getContentByActivity({ status: status.reshared_status, comments: [] }, true).description;
- title += ' | ' + status.reshared_status.text;
- }
-
- const reshared_url = status.reshared_status.uri.replace('douban://douban.com', 'https://www.douban.com/doubanapp/dispatch?uri=');
-
- description += `
原动态:${reshared_url}
`;
- }
-
- // comments
- if (!isRenderingRepost) {
- if (comments.length > 0) {
- description += '
';
- }
- for (const comment of comments) {
- description += `
${comment.text} - ${comment.author.name}`;
- }
- }
-
- description = description.trim().replace(/\n/g, '
');
return { title, description };
}
@@ -147,7 +78,7 @@ module.exports = async (ctx) => {
items
.filter((item) => !item.deleted)
.map((item) => {
- const r = getContentByActivity(item);
+ const r = getContentByActivity(item.status);
return {
title: r.title,
link: item.status.sharing_url,
diff --git a/lib/routes/twitter/user.js b/lib/routes/twitter/user.js
index a5caf0918..06c2f6138 100644
--- a/lib/routes/twitter/user.js
+++ b/lib/routes/twitter/user.js
@@ -37,11 +37,8 @@ module.exports = async (ctx) => {
link: `https://twitter.com/${id}/`,
image: profileImageUrl,
description: userInfo.description,
- item: utils.ProcessFeed(
- {
- data,
- },
- true
- ),
+ item: utils.ProcessFeed({
+ data,
+ }),
};
};
diff --git a/lib/routes/twitter/utils.js b/lib/routes/twitter/utils.js
index afb801d92..d6801a731 100644
--- a/lib/routes/twitter/utils.js
+++ b/lib/routes/twitter/utils.js
@@ -2,7 +2,7 @@ const URL = require('url');
const config = require('@/config').value;
const Twit = require('twit');
-const ProcessFeed = ({ data = [] }, showAuthor = false, showAuthorInTitle = false) => {
+const ProcessFeed = ({ data = [] }, showAuthor = false) => {
const getQueryParams = (url) => URL.parse(url, true).query;
const getOrigionImg = (url) => {
// https://greasyfork.org/zh-CN/scripts/2312-resize-image-on-open-image-in-new-tab/code#n150
@@ -28,12 +28,7 @@ const ProcessFeed = ({ data = [] }, showAuthor = false, showAuthorInTitle = fals
};
const replaceBreak = (text) => text.replace(/
|
/g, ' ');
- const formatText = (text) =>
- text
- .replace(/https:\/\/t\.co(.*)/g, '')
- .trim()
- .replace(/\n/g, '
');
- const formatTextToPlain = (text) => text.replace(/https:\/\/t\.co(.*)/g, '').trim();
+ const formatText = (text) => text.replace(/https:\/\/t\.co(.*)/g, '').replace(/\n/g, '
');
const formatVideo = (media) => {
let content = '';
const video = media.video_info.variants.reduce((video, item) => {
@@ -45,7 +40,7 @@ const ProcessFeed = ({ data = [] }, showAuthor = false, showAuthorInTitle = fals
if (video.url) {
const gifAutoPlayAttr = media.type === 'animated_gif' ? `autoplay loop muted webkit-playsinline playsinline` : '';
- content = ``;
+ content = `
`;
}
return content;
@@ -57,7 +52,6 @@ const ProcessFeed = ({ data = [] }, showAuthor = false, showAuthorInTitle = fals
item.extended_entities.media.forEach((item) => {
// https://developer.twitter.com/en/docs/tweets/data-dictionary/overview/extended-entities-object
let content = '';
- let originImg;
switch (item.type) {
case 'animated_gif':
case 'video':
@@ -66,51 +60,39 @@ const ProcessFeed = ({ data = [] }, showAuthor = false, showAuthorInTitle = fals
case 'photo':
default:
- originImg = getOrigionImg(item.media_url_https);
- content = `
`;
+ content = `
`;
break;
}
img += content;
});
- if (img) {
- img = `
` + img;
- }
return img;
};
const formatUrl = (item) => {
let url = '';
item.entities.urls.forEach((u) => {
- url += `
${u.expanded_url}`;
+ url += `${u.expanded_url}`;
});
return url;
};
return data.map((item) => {
- const originalItem = item;
item = item.retweeted_status || item;
item.full_text = formatText(item.full_text);
const img = formatMedia(item);
let url = '';
let quote = '';
- let quoteOnTitle = '';
if (item.is_quote_status) {
const quoteData = item.quoted_status;
if (quoteData) {
const author = quoteData.user;
- quote += `
${author.name}: `;
- quote += `${formatText(quoteData.full_text)}`;
+ quote += `
${author.name}: ${formatText(quoteData.full_text)}
`;
quote += formatMedia(quoteData);
quote += formatUrl(quoteData);
- quoteOnTitle += `| ${author.name}: ${formatTextToPlain(quoteData.full_text)}`;
-
- quote += `
Source: https://twitter.com/${author.screen_name}/status/${quoteData.id_str}`;
- quote += '
' + new Date(quoteData.created_at).toLocaleString();
- quote += `
`;
} else {
url = formatUrl(item);
}
@@ -119,13 +101,11 @@ const ProcessFeed = ({ data = [] }, showAuthor = false, showAuthorInTitle = fals
}
return {
- title:
- originalItem.user.name +
- `: ${originalItem === item ? '' : '🔁 '}${showAuthorInTitle || originalItem !== item ? item.user.name + ': ' : ''}${item.in_reply_to_screen_name ? '↩️ ' : ''}${replaceBreak(item.full_text)}${quoteOnTitle}`,
- author: originalItem.user.name,
- description: `${
- showAuthor ? `
${item.user.name}: ` : ''
- }${item.in_reply_to_screen_name ? '🔁 ' : ''}${item.full_text}${url}${img}${quote}
${new Date(item.created_at).toLocaleString()}`,
+ title: `${showAuthor ? item.user.name + ': ' : ''}${item.in_reply_to_screen_name ? 'Re ' : ''}${replaceBreak(item.full_text)}`,
+ author: item.user.name,
+ description: `${showAuthor ? `
${item.user.name}:
` : ''}${item.in_reply_to_screen_name ? 'Re ' : ''}${
+ item.full_text
+ }${url}${img}${quote}`,
pubDate: new Date(item.created_at).toUTCString(),
link: `https://twitter.com/${item.user.screen_name}/status/${item.id_str}`,
};
diff --git a/lib/routes/weibo/user.js b/lib/routes/weibo/user.js
index 62fcba715..ed3e2a19c 100644
--- a/lib/routes/weibo/user.js
+++ b/lib/routes/weibo/user.js
@@ -49,10 +49,6 @@ module.exports = async (ctx) => {
const isDataOK = data !== undefined && data.text;
if (isDataOK) {
item.mblog.text = data.text;
- item.mblog.created_at = data.created_at;
- if (item.mblog.retweeted_status && data.retweeted_status) {
- item.mblog.retweeted_status.created_at = data.retweeted_status.created_at;
- }
}
// 转发的长微博处理
const retweet = item.mblog.retweeted_status;
@@ -64,10 +60,8 @@ module.exports = async (ctx) => {
}
const link = `https://weibo.com/${uid}/${item.mblog.bid}`;
- const formatWithRetweet = weiboUtils.formatWithRetweet(item.mblog);
- let description = formatWithRetweet.description;
- const retweetedOrOriginal = formatWithRetweet.retweetedOrOriginal;
- const title = item.mblog.user.screen_name + ': ' + retweetedOrOriginal.replace(/
/g, '[图片]').replace(/<.*?>/g, '');
+ let description = weiboUtils.format(item.mblog);
+ const title = description.replace(/
/g, '[图片]').replace(/<.*?>/g, '');
const pubDate = isDataOK ? new Date(data.created_at).toUTCString() : date(item.mblog.created_at, 8);
// 视频的处理
@@ -80,7 +74,6 @@ module.exports = async (ctx) => {
description: description,
link: link,
pubDate: pubDate,
- author: item.mblog.user.screen_name,
};
return Promise.resolve(it);
})
diff --git a/lib/routes/weibo/utils.js b/lib/routes/weibo/utils.js
index cb3605248..02fac9c5a 100644
--- a/lib/routes/weibo/utils.js
+++ b/lib/routes/weibo/utils.js
@@ -1,11 +1,9 @@
const got = require('@/utils/got');
const weiboUtils = {
- format: (status) => weiboUtils.formatWithRetweet(status).description,
- formatWithRetweet: (status, showAuthorAvatar = true) => {
- let retweetedOrOriginal = '';
+ format: (status) => {
// 长文章的处理
- let temp = (status.longText && status.longText.longTextContent) || status.text || '';
+ let temp = (status.longText && status.longText.longTextContent.replace(/\n/g, '
')) || status.text || '';
// 表情图标转换为文字
temp = temp.replace(/<\/span>/g, '$1');
// 去掉外部链接的图标
@@ -21,43 +19,24 @@ const weiboUtils = {
return decodeURIComponent(p1);
});
- let originalText = temp;
- temp = temp.replace(/\n/g, '
');
-
- // 添加用户名和头像
- let usernameAndAvatar = ``;
- if (showAuthorAvatar) {
- usernameAndAvatar += `
`;
- }
- usernameAndAvatar += `${status.user.screen_name}: `;
- temp = usernameAndAvatar + temp;
-
// 处理转发的微博
if (status.retweeted_status) {
- temp += `
`;
- if (!status.retweeted_status.user) {
- // 当转发的微博被删除时user为null
- status.retweeted_status.user = '微博已删除';
+ // 当转发的微博被删除时user为null
+ if (status.retweeted_status.user) {
+ temp += `
- 转发 @${status.retweeted_status.user.screen_name}: `;
}
// 插入转发的微博
- retweetedOrOriginal += weiboUtils.formatWithRetweet(status.retweeted_status, false).description;
- temp +=
- retweetedOrOriginal +
- `
原博:https://weibo.com/${status.retweeted_status.user.id}/${status.retweeted_status.bid}
` +
- new Date(status.retweeted_status.created_at).toLocaleString() +
- '
';
+ temp += weiboUtils.format(status.retweeted_status);
+ temp += '
';
}
// 添加微博配图
if (status.pics) {
- temp += '
';
status.pics.forEach(function (item) {
- temp += '
';
- originalText += '
';
+ temp += '
';
});
}
-
- return { description: temp, retweetedOrOriginal: status.retweeted_status ? '🔁 ' + retweetedOrOriginal : originalText.replace('\n', '') };
+ return temp;
},
getShowData: async (uid, bid) => {
const link = `https://m.weibo.cn/statuses/show?id=${bid}`;
@@ -79,7 +58,7 @@ const weiboUtils = {
const posterUrl = pagePic ? pagePic.url : '';
const videoUrl = mediaInfo ? mediaInfo.stream_url_hd || mediaInfo.stream_url || mediaInfo.mp4_hd_url || mediaInfo.mp4_sd_url || mediaInfo.mp4_720p_mp4 : '';
if (videoUrl) {
- const video = `
`;
+ const video = `
`;
itemDesc += video;
}
}