diff --git a/core/app/views/refinery/sitemap/index.xml.builder b/core/app/views/refinery/sitemap/index.xml.builder index 8ed9abb293..b5176add2b 100644 --- a/core/app/views/refinery/sitemap/index.xml.builder +++ b/core/app/views/refinery/sitemap/index.xml.builder @@ -4,6 +4,11 @@ xml.urlset "xmlns" => "http://www.sitemaps.org/schemas/sitemap/0.9" do @locales.each do |locale| ::I18n.locale = locale + # request appropriate host & port depending on i18n mode + localized_domain_name = ::Refinery::I18n.domain_name_for_locale(locale) + host_with_port = (::Refinery::I18n.domain_name_enabled? && localized_domain_name) ? + [localized_domain_name, ":", request.port].join : request.host_with_port + ::Refinery::Page.live.in_menu.includes(:parts).each do |page| # exclude sites that are external to our own domain. page_url = if page.url.is_a?(Hash) @@ -11,9 +16,9 @@ xml.urlset "xmlns" => "http://www.sitemaps.org/schemas/sitemap/0.9" do page.url.merge({:only_path => false}) elsif page.url.to_s !~ /^http/ # handle relative link_url addresses. - [request.protocol, request.host_with_port, page.url].join + [request.protocol, host_with_port, page.url].join end - + page_url[:host] = localized_domain_name if (localized_domain_name && page_url.is_a?(Hash)) # Add XML entry only if there is a valid page_url found above. xml.url do xml.loc refinery.url_for(page_url) diff --git a/pages/lib/refinery/pages/url.rb b/pages/lib/refinery/pages/url.rb index 169ded1c03..915201cc0a 100644 --- a/pages/lib/refinery/pages/url.rb +++ b/pages/lib/refinery/pages/url.rb @@ -11,7 +11,8 @@ def url current_url = page.link_url if current_url =~ %r{^/} && - Refinery::I18n.current_frontend_locale != Refinery::I18n.default_frontend_locale + (Refinery::I18n.current_frontend_locale != Refinery::I18n.default_frontend_locale) \ + && !::Refinery::I18n.domain_name_enabled? current_url = "/#{Refinery::I18n.current_frontend_locale}#{current_url}" end diff --git a/pages/spec/lib/refinery/pages/url_spec.rb b/pages/spec/lib/refinery/pages/url_spec.rb index 604868fe43..56f40f39c7 100644 --- a/pages/spec/lib/refinery/pages/url_spec.rb +++ b/pages/spec/lib/refinery/pages/url_spec.rb @@ -29,6 +29,24 @@ module Pages Url::Localised.new(page).url.should eq("/test") end end + + context "when current frontend locale != default frontend locale and domain name enabled" do + it "returns unaltered link_url" do + Refinery::I18n.stub(:current_frontend_locale).and_return(:lv) + Refinery::I18n.stub(:default_frontend_locale).and_return(:en) + Refinery::I18n.stub(:domain_name_enabled?).and_return(true) + Url::Localised.new(page).url.should eq("/test") + end + end + + context "when current frontend locale != default frontend locale and domain name disabled" do + it "returns link_url prefixed with current frontend locale" do + Refinery::I18n.stub(:current_frontend_locale).and_return(:lv) + Refinery::I18n.stub(:default_frontend_locale).and_return(:en) + Refinery::I18n.stub(:domain_name_enabled?).and_return(false) + Url::Localised.new(page).url.should eq("/lv/test") + end + end end end