about summary refs log tree commit diff
path: root/app/lib
diff options
context:
space:
mode:
authorThibaut Girka <thib@sitedethib.com>2019-05-26 22:42:01 +0200
committerThibG <thib@sitedethib.com>2019-05-28 19:33:43 +0200
commit07d4ecfe5e7bff09a6fbe492f477cbe2cb4a1c25 (patch)
tree938863cf9176dda0889979e2f9b748f831fac137 /app/lib
parent18b77224d3ce4ac6aa14278ca2dca34efb0956f5 (diff)
Truncate long URLs while providing alt text for inline images
Diffstat (limited to 'app/lib')
-rw-r--r--app/lib/sanitize_config.rb10
1 files changed, 9 insertions, 1 deletions
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(