diff options
| author | Samantaz Fox <coding@samantaz.fr> | 2022-04-16 20:31:28 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-04-16 20:31:28 +0200 |
| commit | 41301367183803d00cdb27ddf71e08fa5188772f (patch) | |
| tree | 8a57a77d42e3ec922d6c10ddef419efdfda91426 | |
| parent | dda4dadfa3c7aac5ef432ef88b1095d2c6ffe1ba (diff) | |
| parent | 6c122248f595a338e565bf73b1b6e5a2b761b894 (diff) | |
| download | invidious-41301367183803d00cdb27ddf71e08fa5188772f.tar.gz invidious-41301367183803d00cdb27ddf71e08fa5188772f.tar.bz2 invidious-41301367183803d00cdb27ddf71e08fa5188772f.zip | |
Merge pull request #2936 from MathiusD/expand-link
Increase size of links displayed in video description
| -rw-r--r-- | src/invidious/comments.cr | 10 | ||||
| -rw-r--r-- | src/invidious/helpers/utils.cr | 8 |
2 files changed, 15 insertions, 3 deletions
diff --git a/src/invidious/comments.cr b/src/invidious/comments.cr index ab9fcc8b..66cbc4fc 100644 --- a/src/invidious/comments.cr +++ b/src/invidious/comments.cr @@ -574,20 +574,24 @@ def content_to_comment_html(content) if run["navigationEndpoint"]? if url = run["navigationEndpoint"]["urlEndpoint"]?.try &.["url"].as_s url = URI.parse(url) + displayed_url = url if url.host == "youtu.be" url = "/watch?v=#{url.request_target.lstrip('/')}" + displayed_url = "youtube.com#{url}" elsif url.host.nil? || url.host.not_nil!.ends_with?("youtube.com") if url.path == "/redirect" # Sometimes, links can be corrupted (why?) so make sure to fallback # nicely. See https://github.com/iv-org/invidious/issues/2682 url = HTTP::Params.parse(url.query.not_nil!)["q"]? || "" + displayed_url = url else url = url.request_target + displayed_url = "youtube.com#{url}" end end - text = %(<a href="#{url}">#{text}</a>) + text = %(<a href="#{url}">#{reduce_uri(displayed_url)}</a>) elsif watch_endpoint = run["navigationEndpoint"]["watchEndpoint"]? length_seconds = watch_endpoint["startTimeSeconds"]? video_id = watch_endpoint["videoId"].as_s @@ -595,10 +599,10 @@ def content_to_comment_html(content) if length_seconds && length_seconds.as_i > 0 text = %(<a href="javascript:void(0)" data-onclick="jump_to_time" data-jump-time="#{length_seconds}">#{text}</a>) else - text = %(<a href="/watch?v=#{video_id}">#{text}</a>) + text = %(<a href="/watch?v=#{video_id}">#{"youtube.com/watch?v=#{video_id}"}</a>) end elsif url = run.dig?("navigationEndpoint", "commandMetadata", "webCommandMetadata", "url").try &.as_s - text = %(<a href="#{url}">#{text}</a>) + text = %(<a href="#{url}">#{reduce_uri(url)}</a>) end end diff --git a/src/invidious/helpers/utils.cr b/src/invidious/helpers/utils.cr index c1dc17db..8ae5034a 100644 --- a/src/invidious/helpers/utils.cr +++ b/src/invidious/helpers/utils.cr @@ -383,3 +383,11 @@ 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 str.size > max_length + str = "#{str[0, max_length]}#{suffix}" + end + return str +end |
