FIX: keep quoted content in schema data if post excerpt is empty.
This commit is contained in:
parent
2c80e6577f
commit
27da70052f
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue