diff --git a/plugin.rb b/plugin.rb index 5875ba6..ca39388 100644 --- a/plugin.rb +++ b/plugin.rb @@ -230,6 +230,10 @@ SQL ["is_accepted_answer"] end + def get_schema_text(post) + post.excerpt(nil, keep_onebox_body: true).presence || post.excerpt(nil, keep_onebox_body: true, keep_quotes: true) + end + def before_head_close_meta(controller) return "" if !controller.instance_of? TopicsController @@ -248,7 +252,7 @@ SQL question_json = { '@type' => 'Question', 'name' => topic.title, - 'text' => first_post.excerpt(nil, keep_onebox_body: true), + 'text' => get_schema_text(first_post), 'upvoteCount' => first_post.like_count, 'answerCount' => 0, 'dateCreated' => topic.created_at, @@ -262,7 +266,7 @@ SQL question_json['answerCount'] = 1 question_json[:acceptedAnswer] = { '@type' => 'Answer', - 'text' => accepted_answer.excerpt(nil, keep_onebox_body: true), + 'text' => get_schema_text(accepted_answer), 'upvoteCount' => accepted_answer.like_count, 'dateCreated' => accepted_answer.created_at, 'url' => accepted_answer.full_url, diff --git a/spec/requests/topics_controller_spec.rb b/spec/requests/topics_controller_spec.rb index f653b54..67e85eb 100644 --- a/spec/requests/topics_controller_spec.rb +++ b/spec/requests/topics_controller_spec.rb @@ -49,4 +49,15 @@ RSpec.describe TopicsController do expect(response.body).to include(schema_json(1)) end + + it 'should include quoted content in schema information' do + post = topic.first_post + post.raw = "[quote]This is a quoted text.[/quote]" + post.save! + post.rebake! + + get "/t/#{topic.slug}/#{topic.id}" + + expect(response.body).to include('"text":"This is a quoted text."') + end end