diff --git a/app/assets/javascripts/posts.js.erb b/app/assets/javascripts/posts.js.erb index f4581e5ce..368e41da5 100644 --- a/app/assets/javascripts/posts.js.erb +++ b/app/assets/javascripts/posts.js.erb @@ -438,6 +438,7 @@ $("#comments").show(); $("#edit").hide(); $("#share").hide(); + $("#similar").hide(); } else if (e.target.hash === "#edit") { $("#edit").show(); $("#comments").hide(); @@ -445,12 +446,19 @@ $("#post_tag_string").focus().selectEnd().height($("#post_tag_string")[0].scrollHeight); $("#related-tags-button").trigger("click"); $("#find-artist-button").trigger("click"); + $("#similar").hide(); + } else if (e.target.hash === "#similar") { + $("#comments").hide(); + $("#edit").hide(); + $("#share").hide(); + $("#similar").show(); } else { $("#edit").hide(); $("#comments").hide(); $("#share").show(); addthis.init(); - } + $("#similar").hide(); + } $("#post-sections li").removeClass("active"); $(e.target).parent("li").addClass("active"); @@ -460,6 +468,9 @@ $("#post-sections li:first-child").addClass("active"); $("#notes").hide(); $("#edit").hide(); + if ($("#similar").length) { + $("#comments").hide(); + } } Danbooru.Post.resize_ugoira_controls = function() { diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index fe525a3ee..649546155 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -176,7 +176,7 @@ class ApplicationController < ActionController::Base def reset_current_user CurrentUser.user = nil CurrentUser.ip_addr = nil - CurrentUser.root_url = root_url.sub(/\/$/, "") + CurrentUser.root_url = root_url end def set_started_at_session diff --git a/app/logical/post_sets/similar.rb b/app/logical/post_sets/similar.rb index b41166f94..395432f33 100644 --- a/app/logical/post_sets/similar.rb +++ b/app/logical/post_sets/similar.rb @@ -8,7 +8,7 @@ module PostSets def posts @posts ||= begin response = RecommenderService.similar(@post) - post_ids = response.reject {|x| x[0] == @post.id}.slice(0, 5).map {|x| x[0]} + post_ids = response.reject {|x| x[0] == @post.id}.slice(0, 6).map {|x| x[0]} ::Post.find(post_ids) end end diff --git a/app/models/recommender_service.rb b/app/models/recommender_service.rb index 999da429b..7d13a061d 100644 --- a/app/models/recommender_service.rb +++ b/app/models/recommender_service.rb @@ -6,10 +6,16 @@ module RecommenderService end def available?(post) + return true if Rails.env.development? + enabled? && CurrentUser.id == 1 && post.created_at > 6.months.ago && post.score >= 10 end def similar(post) + if Danbooru.config.recommender_server == "development" + return Post.order("random()").limit(6).map {|x| [x.id, "1.000"]} + end + Cache.get("rss:#{post.id}", 1.day) do resp = HTTParty.get( "#{Danbooru.config.recommender_server}/similar/#{post.id}", diff --git a/app/views/posts/show.html.erb b/app/views/posts/show.html.erb index 260421775..685d8577f 100644 --- a/app/views/posts/show.html.erb +++ b/app/views/posts/show.html.erb @@ -82,22 +82,30 @@ <% end %> - <% if RecommenderService.available?(@post) %> - <%= render "posts/partials/index/similar", post: @post %> - <% end %> - <% if @post.presenter.has_nav_links?(self) %> <%= render "posts/partials/show/nav_links", :post => @post, :position => "bottom" %> <% end %> + <% if RecommenderService.available?(@post) %> +
  • Similar
  • + <% end %> +
  • Comments
  • + <% if CurrentUser.is_member? && @post.visible? %>
  • Edit
  • <% end %> +
  • Share
  • + <% if RecommenderService.available?(@post) %> +
    + <%= render "posts/partials/index/similar", post: @post %> +
    + <% end %> +
    <% if !CurrentUser.user.is_builder? %>

    Before commenting, read the <%= link_to "how to comment guide", wiki_pages_path(:search => {:title => "howto:comment"}) %>.