From ad1b7c9608bf32c3a991580347302a071d5902d9 Mon Sep 17 00:00:00 2001 From: Arpit Jalan Date: Wed, 22 Nov 2023 21:22:22 +0530 Subject: [PATCH] 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 --- plugin.rb | 8 +++++--- spec/requests/topics_controller_spec.rb | 8 +++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/plugin.rb b/plugin.rb index 78eb7f3..d0430ed 100644 --- a/plugin.rb +++ b/plugin.rb @@ -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 diff --git a/spec/requests/topics_controller_spec.rb b/spec/requests/topics_controller_spec.rb index e2c1186..fc3841b 100644 --- a/spec/requests/topics_controller_spec.rb +++ b/spec/requests/topics_controller_spec.rb @@ -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 - '' % + '' % # 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