diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 12481db75..daa46ce9c 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -80,9 +80,10 @@ module ApplicationHelper time_tag(time.strftime("%Y-%m-%d %H:%M"), time) end - def external_link_to(url, truncate: nil, strip_scheme: false, link_options: {}) + def external_link_to(url, truncate: nil, strip: false, link_options: {}) text = url - text = text.gsub(%r!\Ahttps?://!i, "") if strip_scheme + text = text.gsub(%r!\Ahttps?://!i, "") if strip == :scheme + text = text.gsub(%r!\Ahttps?://(?:www\.)?!i, "") if strip == :subdomain text = text.truncate(truncate) if truncate if url =~ %r!\Ahttps?://!i diff --git a/app/helpers/posts_helper.rb b/app/helpers/posts_helper.rb index 07edfa111..6ce8c0f41 100644 --- a/app/helpers/posts_helper.rb +++ b/app/helpers/posts_helper.rb @@ -59,29 +59,11 @@ module PostsHelper end def post_source_tag(post) - if post.source =~ %r!\Ahttp://img\d+\.pixiv\.net/img/([^\/]+)/!i - text = "pixiv/#{wordbreakify($1)}".html_safe - source_search = "source:pixiv/#{$1}/" - elsif post.source =~ %r!\Ahttp://i\d\.pixiv\.net/img\d+/img/([^\/]+)/!i - text = "pixiv/#{wordbreakify($1)}".html_safe - source_search = "source:pixiv/#{$1}/" - elsif post.source =~ %r{\Ahttps?://}i - text = post.normalized_source.sub(/\Ahttps?:\/\/(?:www\.)?/i, "") - text = truncate(text, length: 20) - source_search = "source:#{post.source.sub(/[^\/]*$/, "")}" - end - # Only allow http:// and https:// links. Disallow javascript: links. - if post.normalized_source =~ %r!\Ahttps?://!i - source_link = link_to(text, post.normalized_source) + if post.source =~ %r!\Ahttps?://!i + external_link_to(post.normalized_source, strip: :subdomain, truncate: 20) + " ".html_safe + link_to("ยป", post.source, rel: :nofollow) else - source_link = truncate(post.source, :length => 100) - end - - if CurrentUser.is_builder? && !source_search.blank? - source_link + " ".html_safe + link_to("»".html_safe, posts_path(:tags => source_search), :rel => "nofollow") - else - source_link + truncate(post.source, length: 100) end end diff --git a/app/views/related_tags/_source_tags.html.erb b/app/views/related_tags/_source_tags.html.erb index 7f18b6fc9..84c32f661 100644 --- a/app/views/related_tags/_source_tags.html.erb +++ b/app/views/related_tags/_source_tags.html.erb @@ -19,10 +19,10 @@ <% artist.sorted_urls.each do |url| %>
  • <% if url.is_active %> - <%= external_link_to url.url, truncate: 64, strip_scheme: true, link_options: {target: "_blank"} %> + <%= external_link_to url.url, truncate: 64, strip: :scheme, link_options: {target: "_blank"} %> <%= link_to tag.i(class: "fas fa-minus-circle"), artist_url_path(id: url.id, artist_url: { is_active: false }), remote: true, method: :put, "data-confirm": "This will mark the URL as inactive. Continue?" %> <% else %> - <%= external_link_to url.url, truncate: 64, strip_scheme: true, link_options: {target: "_blank"} %> + <%= external_link_to url.url, truncate: 64, strip: :scheme, link_options: {target: "_blank"} %> <% end %>
  • <% end %>