Truncate long URLs while providing alt text for inline images

master
Thibaut Girka 2019-05-26 22:42:01 +02:00 committed by multiple creatures
parent c0a29cdb71
commit 119852adab
1 changed files with 9 additions and 1 deletions

View File

@ -32,7 +32,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
QUERY_STRING_SANITIZER = lambda do |env|