mirror of
https://github.com/ecency/ecency-mobile.git
synced 2024-11-24 17:09:13 +03:00
minimized images and handled different kind image url
This commit is contained in:
parent
694ae454fd
commit
65c92982b1
@ -12,7 +12,7 @@ export const parsePost = (post, currentUserName) => {
|
||||
}
|
||||
|
||||
post.json_metadata = JSON.parse(post.json_metadata);
|
||||
post.image = postImage(post.json_metadata);
|
||||
post.image = postImage(post.json_metadata, post.body);
|
||||
post.pending_payout_value = parseFloat(post.pending_payout_value).toFixed(2);
|
||||
post.created = getTimeFromNow(post.created);
|
||||
post.vote_count = post.active_votes.length;
|
||||
@ -52,11 +52,30 @@ export const parsePost = (post, currentUserName) => {
|
||||
|
||||
const isVoted = (activeVotes, currentUserName) => activeVotes.some(v => v.voter === currentUserName && v.percent > 0);
|
||||
|
||||
const postImage = (metaData) => {
|
||||
const postImage = (metaData, body) => {
|
||||
const markdownImageRegex = /!\[[^\]]*\]\((.*?)\s*("(?:.*[^"])")?\s*\)/g;
|
||||
const urlRegex = /(http|ftp|https):\/\/([\w_-]+(?:(?:\.[\w_-]+)+))([\w.,@?^=%&:/~+#-]*[\w@?^=%&/~+#-])?/gm;
|
||||
const imageRegex = /(http(s?):)([/|.|\w|\s|-])*\.(?:jpg|gif|png)/g;
|
||||
let imageLink;
|
||||
|
||||
if (metaData && metaData.image && metaData.image[0]) {
|
||||
return `https://cdn.steemitimages.com/300x0/${metaData.image[0]}`;
|
||||
imageLink = metaData.image[0];
|
||||
} else if (markdownImageRegex.test(body)) {
|
||||
const markdownMatch = body.match(markdownImageRegex);
|
||||
if (markdownMatch) {
|
||||
const firstMarkdownMatch = markdownMatch[0];
|
||||
imageLink = firstMarkdownMatch.match(urlRegex)[0];
|
||||
}
|
||||
}
|
||||
|
||||
if(!imageLink && imageRegex.test(body)) {
|
||||
const imageMatch = body.match(imageRegex);
|
||||
imageLink = imageMatch[0];
|
||||
}
|
||||
|
||||
if (imageLink) {
|
||||
return `https://cdn.steemitimages.com/300x0/${imageLink}`;
|
||||
}
|
||||
return '';
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user