From d51c076bf8b7bbfe9ced181be2b5303855ccb1e3 Mon Sep 17 00:00:00 2001 From: Penar Musaraj Date: Thu, 24 Aug 2023 10:07:45 -0400 Subject: [PATCH] FIX: Add site name to sitelinks structured data (#23151) --- app/helpers/application_helper.rb | 1 + spec/helpers/application_helper_spec.rb | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index de0a22b0b12..296b91a45be 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -371,6 +371,7 @@ module ApplicationHelper "@context" => "http://schema.org", "@type" => "WebSite", :url => Discourse.base_url, + :name => SiteSetting.title, :potentialAction => { "@type" => "SearchAction", :target => "#{Discourse.base_url}/search?q={search_term_string}", diff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rb index 50d6f419947..74293e13614 100644 --- a/spec/helpers/application_helper_spec.rb +++ b/spec/helpers/application_helper_spec.rb @@ -161,7 +161,19 @@ RSpec.describe ApplicationHelper do it "will return sitelinks search tag" do helper.stubs(:current_page?).returns(false) helper.stubs(:current_page?).with("/").returns(true) - expect(helper.render_sitelinks_search_tag).to include('"@type":"SearchAction"') + + sitelinks_search_tag = + JSON.parse( + helper + .render_sitelinks_search_tag + .gsub('", ""), + ) + + expect(sitelinks_search_tag["@type"]).to eq("WebSite") + expect(sitelinks_search_tag["potentialAction"]["@type"]).to eq("SearchAction") + expect(sitelinks_search_tag["name"]).to eq(SiteSetting.title) + expect(sitelinks_search_tag["url"]).to eq(Discourse.base_url) end end context "when not on homepage" do @@ -180,6 +192,7 @@ RSpec.describe ApplicationHelper do helper.stubs(:current_page?).returns(false) helper.stubs(:current_page?).with(Discourse.base_path).returns(true) expect(helper.render_sitelinks_search_tag).to include('"@type":"SearchAction"') + expect(helper.render_sitelinks_search_tag).to include("subfolder-base-path") end end context "when not on homepage" do