mirror of
https://github.com/mastodon/mastodon.git
synced 2024-12-27 10:58:33 +00:00
Truncate long URLs while providing alt text for inline images
This commit is contained in:
parent
18b77224d3
commit
07d4ecfe5e
|
@ -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(
|
||||
|
|
Loading…
Reference in a new issue