From 7771c7aa9d8e472b16665fcfb97fea8f122f7ebc Mon Sep 17 00:00:00 2001 From: "Jocelyn Badgley (Twipped)" Date: Thu, 5 Mar 2020 10:05:21 -0800 Subject: [PATCH] If there is only one media item on a tweet, ditch the aspect limitation --- build/lib/tweetparse.js | 53 ++++++++++++++++++++++------------------- scss/_tweet.scss | 41 +++++++++++++++++++++---------- templates/tweet.hbs | 28 ++++++++++++++-------- 3 files changed, 75 insertions(+), 47 deletions(-) diff --git a/build/lib/tweetparse.js b/build/lib/tweetparse.js index 8c7d64b..c8b6740 100644 --- a/build/lib/tweetparse.js +++ b/build/lib/tweetparse.js @@ -16,6 +16,7 @@ const schema = { entities: { media: [ { type: true, media_url_https: true, + dimensions: true, video_info: { variants: [ { url: true, content_type: true, @@ -50,31 +51,35 @@ var entityProcessors = { }, media (media, tweet) { - media.forEach((mediaObj) => { - tweet.html = tweet.html.replace(mediaObj.url, ''); + media.forEach((m) => { + tweet.html = tweet.html.replace(m.url, ''); + let width, height; + + if (has(m, 'video_info.aspect_ratio')) { + [ width, height ] = m.video_info.aspect_ratio; + } else if (has(m, 'sizes.medium')) { + ({ width, height } = m.sizes.medium); + } + + if (width && height) { + const ratioH = Math.round((height / width) * 100); + const ratioW = Math.round((width / height) * 100); + let orientation = 'wide'; + if (ratioH > 100) { + orientation = 'tall'; + } else if (ratioH === 100) { + orientation = 'square'; + } + + m.dimensions = { + width, + height, + ratioH, + ratioW, + orientation, + }; + } return; - - // if (mediaObj.type === 'photo') { - // // Use HTTPS if available - // var src = mediaObj.media_url_https ? mediaObj.media_url_https : mediaObj.media_url; - - // if (options && - // options.photoSize && - // mediaObj.sizes && - // mediaObj.sizes[options.photoSize]) { - // // If specified size is available, patch image src to use it - // src = src + ':' + options.photoSize; - // } - - // tweet.html = tweet.html.replace(mediaObj.url, ``); - // } else if (mediaObj.type === 'video') { - // var source = ''; - // mediaObj.video_info.variants.forEach((info) => { - // source += ``; - // }); - // var video = ``; - // tweet.html = tweet.html.replace(mediaObj.url, video); - // } }); }, }; diff --git a/scss/_tweet.scss b/scss/_tweet.scss index 4c1d796..fe5a4ee 100644 --- a/scss/_tweet.scss +++ b/scss/_tweet.scss @@ -189,29 +189,44 @@ grid-template: 1fr 1fr / 1fr 1fr; height: 100%; - &.count1 .tweet-entity { - grid-row-end: span 2; - grid-column-end: span 2; - } - - &.count2 .tweet-entity { - grid-row-end: span 2; - } - - &.count3 .tweet-entity:first-child { - grid-row-end: span 2; - } - .tweet-entity { display: flex; align-items: stretch; justify-content: stretch; + img { + visibility: hidden; + max-width: 100%; + } } .tweet-entity > * { flex: 1; } } + + &.entity-count-1 { + .tweet-entities-inner { + padding-bottom: 0; + > div {position: relative;} + } + + .tweet-entities-grid { + display: block; + } + } + + &.entity-count-1 .tweet-entity { + grid-row-end: span 2; + grid-column-end: span 2; + } + + &.entity-count-2 .tweet-entity { + grid-row-end: span 2; + } + + &.entity-count-3 .tweet-entity:first-child { + grid-row-end: span 2; + } } .tweet-photo { diff --git a/templates/tweet.hbs b/templates/tweet.hbs index 65090ba..1e7a042 100644 --- a/templates/tweet.hbs +++ b/templates/tweet.hbs @@ -32,19 +32,27 @@ {{/with}}{{/if}}
{{{html}}}
{{#any extended_entities.media entities.media}} -