File tree Expand file tree Collapse file tree 2 files changed +14
-3
lines changed Expand file tree Collapse file tree 2 files changed +14
-3
lines changed Original file line number Diff line number Diff line change @@ -587,18 +587,18 @@ def content_to_comment_html(content)
587587 end
588588 end
589589
590- text = %( <a href="#{ url } ">#{ text } </a>)
590+ text = %( <a href="#{ url } ">#{ reduce_uri(url) } </a>)
591591 elsif watch_endpoint = run[" navigationEndpoint" ][" watchEndpoint" ]?
592592 length_seconds = watch_endpoint[" startTimeSeconds" ]?
593593 video_id = watch_endpoint[" videoId" ].as_s
594594
595595 if length_seconds && length_seconds.as_i > 0
596596 text = %( <a href="javascript:void(0)" data-onclick="jump_to_time" data-jump-time="#{ length_seconds } ">#{ text } </a>)
597597 else
598- text = %( <a href="/watch?v=#{ video_id } ">#{ text } </a>)
598+ text = %( <a href="/watch?v=#{ video_id } ">#{ reduce_uri( " /watch?v= #{ video_id } " ) } </a>)
599599 end
600600 elsif url = run.dig?(" navigationEndpoint" , " commandMetadata" , " webCommandMetadata" , " url" ).try & .as_s
601- text = %( <a href="#{ url } ">#{ text } </a>)
601+ text = %( <a href="#{ url } ">#{ reduce_uri(url) } </a>)
602602 end
603603 end
604604
Original file line number Diff line number Diff line change @@ -365,3 +365,14 @@ def fetch_random_instance
365365
366366 return filtered_instance_list.sample(1 )[0 ]
367367end
368+
369+ def reduce_uri (uri : URI | String , max_length : Int32 ? = 50 , suffix : String ? = " ..." ) : String
370+ str = uri.to_s.sub(/https?:\/\/ / , " " )
371+ if ! max_length.nil? && str.size > max_length
372+ str = str[0 , max_length]
373+ if ! suffix.nil?
374+ str = " #{ str } #{ suffix } "
375+ end
376+ end
377+ return str
378+ end
You can’t perform that action at this time.
0 commit comments