Skip to content

Commit ad1b7c9

Browse files
author
Arpit Jalan
authored
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
1 parent bc9b8c4 commit ad1b7c9

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

plugin.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -303,10 +303,11 @@ def before_head_close_meta(controller)
303303
"text" => get_schema_text(first_post),
304304
"upvoteCount" => first_post.like_count,
305305
"answerCount" => 0,
306-
"dateCreated" => topic.created_at,
306+
"datePublished" => topic.created_at,
307307
"author" => {
308308
"@type" => "Person",
309-
"name" => topic.user&.name,
309+
"name" => topic.user&.username,
310+
"url" => topic.user&.full_url,
310311
},
311312
}
312313

@@ -319,11 +320,12 @@ def before_head_close_meta(controller)
319320
"@type" => "Answer",
320321
"text" => get_schema_text(accepted_answer),
321322
"upvoteCount" => accepted_answer.like_count,
322-
"dateCreated" => accepted_answer.created_at,
323+
"datePublished" => accepted_answer.created_at,
323324
"url" => accepted_answer.full_url,
324325
"author" => {
325326
"@type" => "Person",
326327
"name" => accepted_answer.user&.username,
328+
"url" => accepted_answer.user&.full_url,
327329
},
328330
}
329331
else

spec/requests/topics_controller_spec.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,28 +10,30 @@
1010
def schema_json(answerCount)
1111
if answerCount > 0
1212
answer_json =
13-
',"acceptedAnswer":{"@type":"Answer","text":"%{answer_text}","upvoteCount":%{answer_likes},"dateCreated":"%{answered_at}","url":"%{answer_url}","author":{"@type":"Person","name":"%{username2}"}}' %
13+
',"acceptedAnswer":{"@type":"Answer","text":"%{answer_text}","upvoteCount":%{answer_likes},"datePublished":"%{answered_at}","url":"%{answer_url}","author":{"@type":"Person","name":"%{username2}","url":"%{user2_url}"}}' %
1414
{
1515
answer_text: p2.excerpt,
1616
answer_likes: p2.like_count,
1717
answered_at: p2.created_at.as_json,
1818
answer_url: p2.full_url,
1919
username2: p2.user&.username,
20+
user2_url: p2.user&.full_url,
2021
}
2122
else
2223
answer_json = ""
2324
end
2425

2526
# rubocop:todo Layout/LineLength
26-
'<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>' %
27+
'<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>' %
2728
# rubocop:enable Layout/LineLength
2829
{
2930
title: topic.title,
3031
question_text: p1.excerpt,
3132
question_likes: p1.like_count,
3233
answerCount: answerCount,
3334
created_at: topic.created_at.as_json,
34-
username1: topic.user&.name,
35+
username1: topic.user&.username,
36+
user1_url: topic.user&.full_url,
3537
answer_json: answer_json,
3638
}
3739
end

0 commit comments

Comments
 (0)