From: Thibaut Girka Date: Sun, 26 May 2019 20:42:01 +0000 (+0200) Subject: Truncate long URLs while providing alt text for inline images X-Git-Url: https://git.xn--scling-oua.cat.family/?a=commitdiff_plain;h=07d4ecfe5e7bff09a6fbe492f477cbe2cb4a1c25;p=mastodon.git Truncate long URLs while providing alt text for inline images --- diff --git a/app/lib/sanitize_config.rb b/app/lib/sanitize_config.rb index a9a2351a4..e6e861eb9 100644 --- a/app/lib/sanitize_config.rb +++ b/app/lib/sanitize_config.rb @@ -27,7 +27,15 @@ class Sanitize node.name = 'a' node['href'] = node['src'] - node.content = "[🖼 #{node['alt'] || node['href']}]" + if node['alt'].present? + node.content = "[🖼 #{node['alt']}]" + else + url = node['href'] + prefix = url.match(/\Ahttps?:\/\/(www\.)?/).to_s + text = url[prefix.length, 30] + text = text + "…" if url[prefix.length..-1].length > 30 + node.content = "[🖼 #{text}]" + end end MASTODON_STRICT ||= freeze_config(