Fetch external links favicon and add to about page

This commit is contained in:
syeopite 2021-04-15 23:20:44 -07:00
parent e8015fc144
commit 9c3a932217
No known key found for this signature in database
GPG key ID: 6FA616E5A5294A82
3 changed files with 38 additions and 3 deletions

View file

@ -17,7 +17,7 @@ struct AboutChannel
property allowed_regions : Array(String)
property related_channels : Array(AboutRelatedChannel)
property tabs : Array(String)
property links : Array(Tuple(String, String))
property links : Array(Tuple(String, String, String))
end
struct AboutRelatedChannel
@ -125,7 +125,7 @@ def get_about_info(ucid, locale)
total_views = 0_i64
joined = Time.unix(0)
tabs = [] of String
links = [] of {String, String}
links = [] of {String, String, String}
tabs_json = initdata["contents"]["twoColumnBrowseResultsRenderer"]["tabs"]?.try &.as_a?
if !tabs_json.nil?
@ -146,6 +146,7 @@ def get_about_info(ucid, locale)
channel_about_meta["primaryLinks"]?.try &.as_a.each do |link|
link_title = link["title"]["simpleText"].as_s
link_url = URI.parse(link["navigationEndpoint"]["urlEndpoint"]["url"].to_s)
link_icon_url = link["icon"]?.try &.["thumbnails"][0]["url"].to_s || ""
if {"m.youtube.com", "www.youtube.com", "youtu.be"}.includes? link_url.host
if link_url.path == "/redirect"
@ -157,7 +158,7 @@ def get_about_info(ucid, locale)
link_url = link_url.to_s
end
links << {link_title, link_url}
links << {link_title, link_url, link_icon_url}
end
country = channel_about_meta["country"]?.try &.["simpleText"].as_s || ""

View file

@ -27,6 +27,7 @@
<h3> <%= translate(locale, "Links") %> </h3>
<% channel.links.each do |link_tuple| %>
<p class="pure-u-11-24">
<img src="/fetch_link_favicon?url=<%=link_tuple[2]%>">
<a href="<%=link_tuple[1]%>"><%=link_tuple[0]%></a>
</p>
<% end %>