mirror of
https://github.com/discourse/discourse.git
synced 2025-06-03 19:39:30 +08:00
DEV: output sitelinks search tag on homepage only (#16157)
Output sitelinks search tag on homepage only
This commit is contained in:
@ -338,6 +338,7 @@ module ApplicationHelper
|
||||
end
|
||||
|
||||
def render_sitelinks_search_tag
|
||||
if current_page?('/') || current_page?(Discourse.base_path)
|
||||
json = {
|
||||
'@context' => 'http://schema.org',
|
||||
'@type' => 'WebSite',
|
||||
@ -350,6 +351,7 @@ module ApplicationHelper
|
||||
}
|
||||
content_tag(:script, MultiJson.dump(json).html_safe, type: 'application/ld+json')
|
||||
end
|
||||
end
|
||||
|
||||
def gsub_emoji_to_unicode(str)
|
||||
Emoji.gsub_emoji_to_unicode(str)
|
||||
|
@ -100,6 +100,45 @@ RSpec.describe ApplicationHelper do
|
||||
end
|
||||
end
|
||||
|
||||
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" do
|
||||
context "when a dark color scheme is active" do
|
||||
before do
|
||||
|
Reference in New Issue
Block a user