A platform for community discussion. Free, open, simple.
DEV: output sitelinks search tag on homepage only (#16157)
Ayke Halder7277a9fbb37f
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rbindex fdc40fc444e..0ee00f928ca 100644--- a/app/helpers/application_helper.rb+++ b/app/helpers/application_helper.rb@@ -338,17 +338,19 @@ module ApplicationHelperenddef render_sitelinks_search_tag- json = {- '@context' => 'http://schema.org',- '@type' => 'WebSite',- url: Discourse.base_url,- potentialAction: {- '@type' => 'SearchAction',- target: "#{Discourse.base_url}/search?q={search_term_string}",- 'query-input' => 'required name=search_term_string',+ if current_page?('/') || current_page?(Discourse.base_path)+ json = {+ '@context' => 'http://schema.org',+ '@type' => 'WebSite',+ url: Discourse.base_url,+ potentialAction: {+ '@type' => 'SearchAction',+ target: "#{Discourse.base_url}/search?q={search_term_string}",+ 'query-input' => 'required name=search_term_string',+ }}- }- content_tag(:script, MultiJson.dump(json).html_safe, type: 'application/ld+json')+ content_tag(:script, MultiJson.dump(json).html_safe, type: 'application/ld+json')+ endenddef gsub_emoji_to_unicode(str)diff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rbindex f4c25c979a2..ee2f1cdc97f 100644--- a/spec/helpers/application_helper_spec.rb+++ b/spec/helpers/application_helper_spec.rb@@ -100,6 +100,45 @@ RSpec.describe ApplicationHelper doendend+ describe "render_sitelinks_search_tag" do+ context "for non-subfolder install" do+ context "when on homepage" 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"')+ end+ end+ context "when not on homepage" do+ it "will not return sitelinks search tag" do+ helper.stubs(:current_page?).returns(true)+ helper.stubs(:current_page?).with('/').returns(false)+ helper.stubs(:current_page?).with(Discourse.base_path).returns(false)+ expect(helper.render_sitelinks_search_tag).to be_nil+ end+ end+ end+ context "for subfolder install" do+ context "when on homepage" do+ it "will return sitelinks search tag" do+ Discourse.stubs(:base_path).returns('/subfolder-base-path/')+ 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"')+ end+ end+ context "when not on homepage" do+ it "will not return sitelinks search tag" do+ Discourse.stubs(:base_path).returns('/subfolder-base-path/')+ helper.stubs(:current_page?).returns(true)+ helper.stubs(:current_page?).with('/').returns(false)+ helper.stubs(:current_page?).with(Discourse.base_path).returns(false)+ expect(helper.render_sitelinks_search_tag).to be_nil+ end+ end+ end+ end+describe "application_logo_url" docontext "when a dark color scheme is active" dobefore do