fix(route)(weibo): retweeted video/article; article background color (#9202)

Signed-off-by: Rongrong <15956627+Rongronggg9@users.noreply.github.com>
This commit is contained in:
Rongrong 2022-02-26 09:03:28 +08:00 committed by GitHub
parent c4c6b3cf83
commit c77a1e80a7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 10 deletions

View File

@ -78,12 +78,22 @@ module.exports = async (ctx) => {
// 视频的处理
if (displayVideo === '1') {
description = weiboUtils.formatVideo(description, item);
// 含被转发微博时需要从被转发微博中获取视频
if (item.retweeted_status) {
description = weiboUtils.formatVideo(description, item.retweeted_status);
} else {
description = weiboUtils.formatVideo(description, item);
}
}
// 文章的处理
if (displayArticle === '1') {
description = await weiboUtils.formatArticle(ctx, description, item);
// 含被转发微博时需要从被转发微博中获取文章
if (item.retweeted_status) {
description = await weiboUtils.formatArticle(ctx, description, item.retweeted_status);
} else {
description = await weiboUtils.formatArticle(ctx, description, item);
}
}
return {

View File

@ -94,18 +94,27 @@ module.exports = async (ctx) => {
const link = `https://weibo.com/${uid}/${item.mblog.bid}`;
const formatExtended = weiboUtils.formatExtended(ctx, item.mblog);
let description = formatExtended.description;
const formattedTitle = formatExtended.title;
const title = formattedTitle;
const title = formatExtended.title;
const pubDate = item.mblog.created_at;
// 视频的处理
if (displayVideo === '1') {
description = weiboUtils.formatVideo(description, item.mblog);
// 含被转发微博时需要从被转发微博中获取视频
if (item.mblog.retweeted_status) {
description = weiboUtils.formatVideo(description, item.mblog.retweeted_status);
} else {
description = weiboUtils.formatVideo(description, item.mblog);
}
}
// 文章的处理
if (displayArticle === '1') {
description = await weiboUtils.formatArticle(ctx, description, item.mblog);
// 含被转发微博时需要从被转发微博中获取文章
if (item.mblog.retweeted_status) {
description = await weiboUtils.formatArticle(ctx, description, item.mblog.retweeted_status);
} else {
description = await weiboUtils.formatArticle(ctx, description, item.mblog);
}
}
return {

View File

@ -84,7 +84,7 @@ const weiboUtils = {
html = usernameAndAvatar + html;
}
// 添加文章头图
// 添加文章头图,此处不需要回落到被转发的微博,后续处理被转发的微博时,还会执行到这里
if (status.page_info && status.page_info.type === 'article' && status.page_info.page_pic && status.page_info.page_pic.url) {
// 如果以后后续流程会用到其他字段,记得修改这里
const pagePic = {
@ -92,7 +92,7 @@ const weiboUtils = {
url: status.page_info.page_pic.url,
},
};
// 文章微博本身是没有配图的,但还是要以防万一
// 文章微博一般不会有配图但也有可能有https://weibo.com/6882481489/Lh85BkS3m
if (status.pics) {
status.pics.push(pagePic);
} else {
@ -292,14 +292,15 @@ const weiboUtils = {
const isOriginal = article.is_original;
const isArticleNonFree = article.is_article_free; // 微博起错了字段名,它为 1 时才是收费文章
// 许多微博文章都给文字设置了白色背景,这里也只好使用白色背景了
let html = '<br clear="both" /><br clear="both" />';
html += '<div style="clear: both"></div><div style="background: #60606010;border:1px solid #80808030;margin:0;padding:3% 7%;overflow-wrap: break-word">';
html += '<div style="clear: both"></div><div style="background: #fff;border:5px solid #80808030;margin:0;padding:3% 5%;overflow-wrap: break-word">';
html += `<h1 style="font-size: 1.5rem;line-height: 1.25;color: #333;">${title}</h1>`; // 加入标题
// 加入文章信息
const iconStyle =
'display: inline-block;margin-inline: 0.25rem;width: 2.25rem; height: 1.125rem; background: #e7e7e7; border-radius: 2px; box-sizing: border-box; text-align: center; line-height: 1.0625rem; font-size: 0.75rem; color: #aaa;';
'display: inline-block;margin-inline: 0.25rem;width: 2.25rem; height: 1.125rem; background: #eee; border-radius: 2px; box-sizing: border-box; text-align: center; line-height: 1.0625rem; font-size: 0.75rem; color: #aaa;';
let articleMeta = '<p style="line-height: 1.66; color: #999;margin: 0 0 0.75rem;font-size: 0.75rem;padding: 0">';
if (isArticleNonFree) {
articleMeta += `<span style="${iconStyle}">试读</span> `;