posts: change "»" links next to sources in sidebar.
* On the posts show page, make the "»" link next to the source visible to all users, not just builders. * Make "»" link to the raw unnormalized source, instead of a `source:` search. * Remove the special case for displaying old pixiv sources as `pixiv/moniker`.
This commit is contained in:
@@ -80,9 +80,10 @@ module ApplicationHelper
|
|||||||
time_tag(time.strftime("%Y-%m-%d %H:%M"), time)
|
time_tag(time.strftime("%Y-%m-%d %H:%M"), time)
|
||||||
end
|
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 = 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
|
text = text.truncate(truncate) if truncate
|
||||||
|
|
||||||
if url =~ %r!\Ahttps?://!i
|
if url =~ %r!\Ahttps?://!i
|
||||||
|
|||||||
@@ -59,29 +59,11 @@ module PostsHelper
|
|||||||
end
|
end
|
||||||
|
|
||||||
def post_source_tag(post)
|
def post_source_tag(post)
|
||||||
if post.source =~ %r!\Ahttp://img\d+\.pixiv\.net/img/([^\/]+)/!i
|
|
||||||
text = "pixiv/<wbr>#{wordbreakify($1)}".html_safe
|
|
||||||
source_search = "source:pixiv/#{$1}/"
|
|
||||||
elsif post.source =~ %r!\Ahttp://i\d\.pixiv\.net/img\d+/img/([^\/]+)/!i
|
|
||||||
text = "pixiv/<wbr>#{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.
|
# Only allow http:// and https:// links. Disallow javascript: links.
|
||||||
if post.normalized_source =~ %r!\Ahttps?://!i
|
if post.source =~ %r!\Ahttps?://!i
|
||||||
source_link = link_to(text, post.normalized_source)
|
external_link_to(post.normalized_source, strip: :subdomain, truncate: 20) + " ".html_safe + link_to("»", post.source, rel: :nofollow)
|
||||||
else
|
else
|
||||||
source_link = truncate(post.source, :length => 100)
|
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
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -19,10 +19,10 @@
|
|||||||
<% artist.sorted_urls.each do |url| %>
|
<% artist.sorted_urls.each do |url| %>
|
||||||
<li>
|
<li>
|
||||||
<% if url.is_active %>
|
<% 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?" %>
|
<%= 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 %>
|
<% else %>
|
||||||
<del><%= external_link_to url.url, truncate: 64, strip_scheme: true, link_options: {target: "_blank"} %></del>
|
<del><%= external_link_to url.url, truncate: 64, strip: :scheme, link_options: {target: "_blank"} %></del>
|
||||||
<% end %>
|
<% end %>
|
||||||
</li>
|
</li>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|||||||
Reference in New Issue
Block a user