diff --git a/src/invidious/helpers/utils.cr b/src/invidious/helpers/utils.cr index 7a262f849..ad4b65324 100644 --- a/src/invidious/helpers/utils.cr +++ b/src/invidious/helpers/utils.cr @@ -404,3 +404,13 @@ def invidious_companion_encrypt(data) encrypted_data = encrypt_ecb_without_salt("#{timestamp}|#{data}", CONFIG.invidious_companion_key) return Base64.urlsafe_encode(encrypted_data) end + +# Parses hashtags (#tag) in a text string and wraps them in clickable links. +# The input text should already be HTML-escaped. The hashtag text is kept as-is +# (including the # symbol) within the link, while the URL uses the encoded tag name. +def parse_hashtags_in_text(text : String) : String + text.gsub(/#([\w-]+)/) do |_match| + hashtag = $1 + %(##{hashtag}) + end +end diff --git a/src/invidious/views/components/item.ecr b/src/invidious/views/components/item.ecr index ece2efe8a..61545e593 100644 --- a/src/invidious/views/components/item.ecr +++ b/src/invidious/views/components/item.ecr @@ -78,7 +78,7 @@
<%= HTML.escape(rv["title"]) %>
+ &listen=<%= params.listen %>"><%= parse_hashtags_in_text(HTML.escape(rv["title"])) %>