FIX: make JSON_LD schema consistent with our microdata in core (#269)

* FIX: make JSON_LD schema consistent with our microdata in core

https://meta.discourse.org/t/alignment-of-schema-org-markup-between-qa-solved-dfp-core/279510
This commit is contained in:
Arpit Jalan 2023-11-22 21:22:22 +05:30 committed by GitHub
parent bc9b8c41d4
commit ad1b7c9608
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 6 deletions

View File

@ -303,10 +303,11 @@ SQL
"text" => get_schema_text(first_post),
"upvoteCount" => first_post.like_count,
"answerCount" => 0,
"dateCreated" => topic.created_at,
"datePublished" => topic.created_at,
"author" => {
"@type" => "Person",
"name" => topic.user&.name,
"name" => topic.user&.username,
"url" => topic.user&.full_url,
},
}
@ -319,11 +320,12 @@ SQL
"@type" => "Answer",
"text" => get_schema_text(accepted_answer),
"upvoteCount" => accepted_answer.like_count,
"dateCreated" => accepted_answer.created_at,
"datePublished" => accepted_answer.created_at,
"url" => accepted_answer.full_url,
"author" => {
"@type" => "Person",
"name" => accepted_answer.user&.username,
"url" => accepted_answer.user&.full_url,
},
}
else

View File

@ -10,20 +10,21 @@ RSpec.describe TopicsController do
def schema_json(answerCount)
if answerCount > 0
answer_json =
',"acceptedAnswer":{"@type":"Answer","text":"%{answer_text}","upvoteCount":%{answer_likes},"dateCreated":"%{answered_at}","url":"%{answer_url}","author":{"@type":"Person","name":"%{username2}"}}' %
',"acceptedAnswer":{"@type":"Answer","text":"%{answer_text}","upvoteCount":%{answer_likes},"datePublished":"%{answered_at}","url":"%{answer_url}","author":{"@type":"Person","name":"%{username2}","url":"%{user2_url}"}}' %
{
answer_text: p2.excerpt,
answer_likes: p2.like_count,
answered_at: p2.created_at.as_json,
answer_url: p2.full_url,
username2: p2.user&.username,
user2_url: p2.user&.full_url,
}
else
answer_json = ""
end
# rubocop:todo Layout/LineLength
'<script type="application/ld+json">{"@context":"http://schema.org","@type":"QAPage","name":"%{title}","mainEntity":{"@type":"Question","name":"%{title}","text":"%{question_text}","upvoteCount":%{question_likes},"answerCount":%{answerCount},"dateCreated":"%{created_at}","author":{"@type":"Person","name":"%{username1}"}%{answer_json}}}</script>' %
'<script type="application/ld+json">{"@context":"http://schema.org","@type":"QAPage","name":"%{title}","mainEntity":{"@type":"Question","name":"%{title}","text":"%{question_text}","upvoteCount":%{question_likes},"answerCount":%{answerCount},"datePublished":"%{created_at}","author":{"@type":"Person","name":"%{username1}","url":"%{user1_url}"}%{answer_json}}}</script>' %
# rubocop:enable Layout/LineLength
{
title: topic.title,
@ -31,7 +32,8 @@ RSpec.describe TopicsController do
question_likes: p1.like_count,
answerCount: answerCount,
created_at: topic.created_at.as_json,
username1: topic.user&.name,
username1: topic.user&.username,
user1_url: topic.user&.full_url,
answer_json: answer_json,
}
end