This commit is contained in:
Toks
2013-04-10 19:07:29 -04:00
parent a34184f55b
commit cb263575aa
2 changed files with 14 additions and 5 deletions

View File

@@ -20,15 +20,24 @@ module PostsHelper
def post_source_tag(post)
if post.source =~ %r!http://img\d+\.pixiv\.net/img/([^\/]+)/!
text = "pixiv/#{$1}"
link_to(text, post.normalized_source)
source_link = link_to(text, post.normalized_source)
source_search = "source:#{text}"
elsif post.source =~ %r!http://i\d\.pixiv\.net/img\d+/img/([^\/]+)/!
text = "pixiv/#{$1}"
link_to(text, post.normalized_source)
source_link = link_to(text, post.normalized_source)
source_search = "source:#{text}"
elsif post.source =~ /^http/
text = truncate(post.normalized_source.sub(/^https?:\/\/(?:www)?/, ""))
link_to(truncate(text, :length => 20), post.normalized_source)
source_link = link_to(truncate(text, :length => 20), post.normalized_source)
source_search = "source:#{post.source.sub(/[^\/]*$/, "")}"
else
truncate(post.source, :length => 100)
source_link = truncate(post.source, :length => 100)
end
if CurrentUser.is_builder? && !source_search.blank?
source_link + " " + link_to("»".html_safe, posts_path(:tags => source_search))
else
source_link
end
end
end