From 78c447829a605cfc6b82fb9dcb4e01057a17cec5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9ry=20Mathieu=20=28Mathius=29?= Date: Fri, 25 Feb 2022 02:11:30 +0100 Subject: [PATCH] Increase size of links displayed in video description --- src/invidious/comments.cr | 6 +++--- src/invidious/helpers/utils.cr | 11 +++++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/invidious/comments.cr b/src/invidious/comments.cr index ab9fcc8b9..e2c7b3a03 100644 --- a/src/invidious/comments.cr +++ b/src/invidious/comments.cr @@ -587,7 +587,7 @@ def content_to_comment_html(content) end end - text = %(#{text}) + text = %(#{reduce_uri(url)}) elsif watch_endpoint = run["navigationEndpoint"]["watchEndpoint"]? length_seconds = watch_endpoint["startTimeSeconds"]? video_id = watch_endpoint["videoId"].as_s @@ -595,10 +595,10 @@ def content_to_comment_html(content) if length_seconds && length_seconds.as_i > 0 text = %(#{text}) else - text = %(#{text}) + text = %(#{reduce_uri("/watch?v=#{video_id}")}) end elsif url = run.dig?("navigationEndpoint", "commandMetadata", "webCommandMetadata", "url").try &.as_s - text = %(#{text}) + text = %(#{reduce_uri(url)}) end end diff --git a/src/invidious/helpers/utils.cr b/src/invidious/helpers/utils.cr index a58a21b13..f8a7873d0 100644 --- a/src/invidious/helpers/utils.cr +++ b/src/invidious/helpers/utils.cr @@ -365,3 +365,14 @@ def fetch_random_instance return filtered_instance_list.sample(1)[0] end + +def reduce_uri(uri : URI | String, max_length : Int32? = 50, suffix : String? = "...") : String + str = uri.to_s.sub(/https?:\/\//, "") + if !max_length.nil? && str.size > max_length + str = str[0, max_length] + if !suffix.nil? + str = "#{str}#{suffix}" + end + end + return str +end