summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorOmar Roth <omarroth@hotmail.com>2019-04-14 17:43:44 -0500
committerOmar Roth <omarroth@hotmail.com>2019-04-14 17:43:44 -0500
commitb51fd7fc1325ed0008c5aa7043585013ef62c86a (patch)
tree440e9be00553d4cc47f92d6ba5917b97158a4707 /src
parentefe86c37b2b47384d49330ab282225072e6b08fa (diff)
downloadinvidious-b51fd7fc1325ed0008c5aa7043585013ef62c86a.tar.gz
invidious-b51fd7fc1325ed0008c5aa7043585013ef62c86a.tar.bz2
invidious-b51fd7fc1325ed0008c5aa7043585013ef62c86a.zip
Add view count to video items
Diffstat (limited to 'src')
-rw-r--r--src/invidious/helpers/utils.cr4
-rw-r--r--src/invidious/views/components/item.ecr14
2 files changed, 15 insertions, 3 deletions
diff --git a/src/invidious/helpers/utils.cr b/src/invidious/helpers/utils.cr
index eb8fa80a..eb304d8d 100644
--- a/src/invidious/helpers/utils.cr
+++ b/src/invidious/helpers/utils.cr
@@ -189,7 +189,9 @@ def number_to_short_text(number)
text = text.rchop(".0")
- if number / 1000000 != 0
+ if number / 1_000_000_000 != 0
+ text += "B"
+ elsif number / 1_000_000 != 0
text += "M"
elsif number / 1000 != 0
text += "K"
diff --git a/src/invidious/views/components/item.ecr b/src/invidious/views/components/item.ecr
index e2a5195c..2dc0bea4 100644
--- a/src/invidious/views/components/item.ecr
+++ b/src/invidious/views/components/item.ecr
@@ -71,7 +71,12 @@
<% if item.responds_to?(:premiere_timestamp) && item.premiere_timestamp && item.premiere_timestamp.not_nil! > Time.now %>
<h5><%= translate(locale, "Premieres in `x`", recode_date((item.premiere_timestamp.as(Time) - Time.now).ago, locale)) %></h5>
<% elsif Time.now - item.published > 1.minute %>
- <h5><%= translate(locale, "Shared `x` ago", recode_date(item.published, locale)) %></h5>
+ <h5 class="pure-g">
+ <div class="pure-u-2-3"><%= translate(locale, "Shared `x` ago", recode_date(item.published, locale)) %></div>
+ <div class="pure-u-1-3" style="text-align: right">
+ <%= item.responds_to?(:views) ? translate(locale, "`x` views", number_to_short_text(item.views)) : "" %>
+ </div>
+ </h5>
<% end %>
<% else %>
<% if env.get("preferences").as(Preferences).thin_mode %>
@@ -108,7 +113,12 @@
<% if item.responds_to?(:premiere_timestamp) && item.premiere_timestamp && item.premiere_timestamp.not_nil! > Time.now %>
<h5><%= translate(locale, "Premieres in `x`", recode_date((item.premiere_timestamp.as(Time) - Time.now).ago, locale)) %></h5>
<% elsif Time.now - item.published > 1.minute %>
- <h5><%= translate(locale, "Shared `x` ago", recode_date(item.published, locale)) %></h5>
+ <h5 class="pure-g">
+ <div class="pure-u-2-3"><%= translate(locale, "Shared `x` ago", recode_date(item.published, locale)) %></div>
+ <div class="pure-u-1-3" style="text-align: right">
+ <%= item.responds_to?(:views) ? translate(locale, "`x` views", number_to_short_text(item.views)) : "" %>
+ </div>
+ </h5>
<% end %>
<% end %>
</div>