FIX: Add site name to sitelinks structured data (#23151)

This commit is contained in:
Penar Musaraj 2023-08-24 10:07:45 -04:00 committed by GitHub
parent e2705df0f4
commit d51c076bf8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 1 deletions

View File

@ -371,6 +371,7 @@ module ApplicationHelper
"@context" => "http://schema.org", "@context" => "http://schema.org",
"@type" => "WebSite", "@type" => "WebSite",
:url => Discourse.base_url, :url => Discourse.base_url,
:name => SiteSetting.title,
:potentialAction => { :potentialAction => {
"@type" => "SearchAction", "@type" => "SearchAction",
:target => "#{Discourse.base_url}/search?q={search_term_string}", :target => "#{Discourse.base_url}/search?q={search_term_string}",

View File

@ -161,7 +161,19 @@ RSpec.describe ApplicationHelper do
it "will return sitelinks search tag" do it "will return sitelinks search tag" do
helper.stubs(:current_page?).returns(false) helper.stubs(:current_page?).returns(false)
helper.stubs(:current_page?).with("/").returns(true) 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('<script type="application/ld+json">', "")
.gsub("</script>", ""),
)
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
end end
context "when not on homepage" do context "when not on homepage" do
@ -180,6 +192,7 @@ RSpec.describe ApplicationHelper do
helper.stubs(:current_page?).returns(false) helper.stubs(:current_page?).returns(false)
helper.stubs(:current_page?).with(Discourse.base_path).returns(true) 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('"@type":"SearchAction"')
expect(helper.render_sitelinks_search_tag).to include("subfolder-base-path")
end end
end end
context "when not on homepage" do context "when not on homepage" do