1
0
Fork 0
forked from gitea/nas

Merge remote-tracking branch 'parent/main' into upstream-20240319

This commit is contained in:
KMY 2024-03-19 09:15:20 +09:00
commit 76598bd542
496 changed files with 5795 additions and 3709 deletions

View file

@ -55,6 +55,7 @@ class TextFormatter
class << self
include ERB::Util
include ActionView::Helpers::TagHelper
def shortened_link(url, rel_me: false)
url = Addressable::URI.parse(url).to_s
@ -65,9 +66,11 @@ class TextFormatter
suffix = url[prefix.length + 30..]
cutoff = url[prefix.length..].length > 30
<<~HTML.squish.html_safe # rubocop:disable Rails/OutputSafety
<a href="#{h(url)}" target="_blank" rel="#{rel.join(' ')}" translate="no"><span class="invisible">#{h(prefix)}</span><span class="#{cutoff ? 'ellipsis' : ''}">#{h(display_url)}</span><span class="invisible">#{h(suffix)}</span></a>
HTML
tag.a href: url, target: '_blank', rel: rel.join(' '), translate: 'no' do
tag.span(prefix, class: 'invisible') +
tag.span(display_url, class: (cutoff ? 'ellipsis' : '')) +
tag.span(suffix, class: 'invisible')
end
rescue Addressable::URI::InvalidURIError, IDN::Idna::IdnaError
h(url)
end