* fix(jike user): shorten title and add repost content

* fix #109
This commit is contained in:
Derek 2018-05-13 22:51:22 +08:00 committed by DIYgod
parent 6529fe47a1
commit a7b20283ec
1 changed files with 22 additions and 5 deletions

View File

@ -9,7 +9,7 @@ module.exports = async (ctx) => {
url: 'https://app.jike.ruguoapp.com/1.0/personalUpdate/single',
headers: {
'User-Agent': config.ua,
'Referer': `https://web.okjike.com/user/${id}`,
'Referer': `https://web.okjike.com/user/${id}/post`,
'App-Version': '4.1.0',
'platform': 'web'
},
@ -42,13 +42,30 @@ module.exports = async (ctx) => {
imgTemplate += `<br><img referrerpolicy="no-referrer" src="${item.picUrl}">`;
});
const content = item.content || item.linkInfo && item.linkInfo.title || item.target && item.target.content;
let content = item.content || item.linkInfo && item.linkInfo.title || item.target && item.target.content;
const shortenTitle = content.length > 75 ? `${content.substr(0, 75)}...` : content;
if (item.type === 'REPOST') {
const targetLinkMap = {
'OFFICIAL_MESSAGE': `https://web.okjike.com/message-detail/${item.target.id}/officialMessage`,
'ORIGINAL_POST': `https://web.okjike.com/post-detail/${item.target.id}/originalPost`,
'REPOST': `https://web.okjike.com/post-detail/${item.target.id}/repost`
};
let repostImgTemplate = '';
item.target.pictures && item.target.pictures.forEach((item) => {
repostImgTemplate += `<p><img style="box-shadow: 0 0 1px rgba(0,0,0,.2);" referrerpolicy="no-referrer" src="${item.thumbnailUrl}"></p>`;
});
let repostContent = `<a style="padding:15px;margin-top:10px;display:block;border-radius:4px;background-color:#fff;border:1px solid rgba(0,0,0,.08);text-decoration:none;" href="${targetLinkMap[item.target.type]}" target="_blank"><p>@${item.target.user.screenName}</p>${item.target.content}${repostImgTemplate}</a>`;
content = `${content}${repostContent}`;
}
return {
title: `${typeMap[item.type]}了: ${content}`,
title: `${typeMap[item.type]}了: ${shortenTitle}`,
description: `${content}${linkTemplate}${imgTemplate}`,
pubDate: new Date(item.createdAt).toUTCString(),
link: `https://web.okjike.com/message-detail/${item.id}/officialMessage`
link: `https://web.okjike.com/post-detail/${item.id}/originalPost`
}
}),
};
};
};