Skip to content

A platform for community discussion. Free, open, simple.

FEATURE: Restore the crawler view for post-voting comments (#39636)

Jarek Radosz5265fe712954
diff --git a/plugins/discourse-post-voting/app/serializers/reviewable_post_voting_comments_serializer.rb b/plugins/discourse-post-voting/app/serializers/reviewable_post_voting_comment_serializer.rb
similarity index 100%
rename from plugins/discourse-post-voting/app/serializers/reviewable_post_voting_comments_serializer.rb
rename to plugins/discourse-post-voting/app/serializers/reviewable_post_voting_comment_serializer.rb
diff --git a/plugins/discourse-post-voting/app/views/connectors/after_post_body/comments.html.erb b/plugins/discourse-post-voting/app/views/connectors/after_post_body/comments.html.erb
deleted file mode 100644
index 3585595559c..00000000000
--- a/plugins/discourse-post-voting/app/views/connectors/after_post_body/comments.html.erb
+++ /dev/null
@@ -1,26 +0,0 @@
-<% if @topic_view.topic.is_post_voting? %>
- <div class="post-voting-comments">
- <% @topic_view.comments[post.id]&.each_with_index do |comment, i| %>
- <div class="post-voting-comments__comment">
- <span class="post-voting-comments__comment-cooked" itemprop="comment"><%= comment.cooked.html_safe %></span>
- <span class="post-voting-comments__separator">–</span>
- <span class="post-voting-comments__comment-creator" itemprop="author" itemscope itemtype="http://schema.org/Person">
- <a itemprop="url" href='<%= Discourse.base_url %>/u/<%= comment.user.username %>'><span itemprop="name"><%= comment.user.username %></span></a>
- <time itemprop='datePublished' datetime='<%= comment.created_at.to_formatted_s(:iso8601) %>' class="post-voting-comments__comment-time">
- (<%= l comment.created_at, format: :long %>)
- </time>
- </span>
- </div>
- <% end %>
- </div>
-
- <%
- reply_count = @topic_view.filtered_posts.count - 1
- if post.post_number == 1 && reply_count > 0
- %>
- <div class="post-voting-answer-count">
- <h3><%= t('topic.post-voting.answer_count', count: reply_count) %></h3>
- <span class="post-voting-answer-count__value" itemprop="answerCount"><%= reply_count %></span>
- </div>
- <% end %>
-<% end %>
diff --git a/plugins/discourse-post-voting/app/views/post_voting/crawler_post.html.erb b/plugins/discourse-post-voting/app/views/post_voting/crawler_post.html.erb
new file mode 100644
index 00000000000..701df8629f6
--- /dev/null
+++ b/plugins/discourse-post-voting/app/views/post_voting/crawler_post.html.erb
@@ -0,0 +1,24 @@
+<% if @comments.present? %>
+ <div class="post-voting-comments">
+ <% @comments.each do |comment| %>
+ <% next if comment.user.blank? %>
+ <div class="post-voting-comments__comment" itemprop="comment" itemscope itemtype="http://schema.org/Comment">
+ <span class="post-voting-comments__comment-cooked" itemprop="text"><%= comment.cooked.html_safe %></span>
+ <span class="post-voting-comments__separator">–</span>
+ <span class="post-voting-comments__comment-creator" itemprop="author" itemscope itemtype="http://schema.org/Person">
+ <a rel="nofollow" itemprop="url" href="<%= comment.user.full_url %>"><span itemprop="name"><%= comment.user.username %></span></a>
+ </span>
+ <time itemprop="datePublished" datetime="<%= comment.created_at.iso8601 %>" class="post-voting-comments__comment-time">
+ (<%= l comment.created_at, format: :long %>)
+ </time>
+ </div>
+ <% end %>
+ </div>
+<% end %>
+
+<% if @reply_count > 0 %>
+ <div class="post-voting-answer-count">
+ <h2><%= t("topic.post_voting.answer_count", count: @reply_count) %></h2>
+ <span class="post-voting-answer-count__value"><%= @reply_count %></span>
+ </div>
+<% end %>
diff --git a/plugins/discourse-post-voting/assets/stylesheets/common/post-voting-crawler.scss b/plugins/discourse-post-voting/assets/stylesheets/common/post-voting-crawler.scss
index 5302c997737..539d539f6d2 100644
--- a/plugins/discourse-post-voting/assets/stylesheets/common/post-voting-crawler.scss
+++ b/plugins/discourse-post-voting/assets/stylesheets/common/post-voting-crawler.scss
@@ -8,7 +8,6 @@ body > noscript {
padding-top: var(--space-4);
&__comment {
- display: flex;
border-top: 1px solid var(--primary-low);
padding: var(--space-1) 0;
}
@@ -22,6 +21,10 @@ body > noscript {
display: inline;
margin: 0 var(--space-1);
}
+
+ &__comment-time {
+ margin-left: var(--space-1);
+ }
}
.post-voting-answer-count {
diff --git a/plugins/discourse-post-voting/config/routes.rb b/plugins/discourse-post-voting/config/routes.rb
index 21eeb2d8bbf..f218df8f169 100644
--- a/plugins/discourse-post-voting/config/routes.rb
+++ b/plugins/discourse-post-voting/config/routes.rb
@@ -12,5 +12,3 @@ PostVoting::Engine.routes.draw do
post "vote/comment" => "votes#create_comment_vote"
delete "vote/comment" => "votes#destroy_comment_vote"
end
-
-Discourse::Application.routes.append { mount PostVoting::Engine, at: "post_voting" }
diff --git a/plugins/discourse-post-voting/plugin.rb b/plugins/discourse-post-voting/plugin.rb
index 574f7240d23..d56c56a8391 100644
--- a/plugins/discourse-post-voting/plugin.rb
+++ b/plugins/discourse-post-voting/plugin.rb
@@ -16,8 +16,11 @@ module ::PostVoting
PLUGIN_NAME = "discourse-post-voting"
end
+require_relative "lib/post_voting/engine"
+
after_initialize do
- require_relative "lib/post_voting/engine"
+ Discourse::Application.routes.append { mount PostVoting::Engine, at: "post_voting" }
+
require_relative "lib/post_voting/vote_manager"
require_relative "lib/post_voting/guardian_extension"
require_relative "lib/post_voting/comment_creator"
@@ -38,8 +41,7 @@ after_initialize do
require_relative "app/models/reviewable_post_voting_comment"
require_relative "app/serializers/basic_voter_serializer"
require_relative "app/serializers/post_voting_comment_serializer"
- require_relative "app/serializers/reviewable_post_voting_comments_serializer"
- require_relative "config/routes"
+ require_relative "app/serializers/reviewable_post_voting_comment_serializer"
register_svg_icon "vote-up"
register_svg_icon "vote-up-filled"
@@ -112,6 +114,24 @@ after_initialize do
end
end
+ register_html_builder("server:topic-show-crawler-post-end") do |controller, post:|
+ topic_view = controller.instance_variable_get(:@topic_view)
+ next if !topic_view&.topic&.is_post_voting?
+
+ comments = topic_view.comments[post.id]
+ reply_count = post.is_first_post? ? topic_view.filtered_posts.count - 1 : 0
+ next if comments.blank? && reply_count <= 0
+
+ ApplicationController.render(
+ template: "post_voting/crawler_post",
+ layout: false,
+ assigns: {
+ comments: comments,
+ reply_count: reply_count,
+ },
+ )
+ end
+
TopicView.on_preload do |topic_view|
next if !topic_view.topic.is_post_voting?
diff --git a/plugins/discourse-post-voting/spec/requests/topics_controller_spec.rb b/plugins/discourse-post-voting/spec/requests/topics_controller_spec.rb
index 57ee59a907b..e907d202d9c 100644
--- a/plugins/discourse-post-voting/spec/requests/topics_controller_spec.rb
+++ b/plugins/discourse-post-voting/spec/requests/topics_controller_spec.rb
@@ -51,21 +51,14 @@ describe TopicsController do
)
end
- it "includes post_voting comments for crawler view" do
- skip "temporarily disable crawler view test while the perf issues are being worked on"
-
- get "/t/#{topic.slug}/#{topic.id}.html"
+ it "includes post_voting comments in crawler view" do
+ get "/t/#{topic.slug}/#{topic.id}", env: { "HTTP_USER_AGENT" => "Googlebot" }
expect(response.status).to eq(200)
-
- crawler_html = response.body
-
- expect(crawler_html).to match(
- %r{<span class="post-voting-comments__comment-cooked" itemprop="comment"><p>this is a comment!</p></span>},
- )
- expect(crawler_html).to match(
- %r{<span class="post-voting-answer-count__value" itemprop="answerCount">3</span>},
+ expect(response.body).to match(
+ %r{<span class="post-voting-comments__comment-cooked" itemprop="text"><p>this is a comment!</p></span>},
)
+ expect(response.body).to match(%r{<span class="post-voting-answer-count__value">3</span>})
end
end
end