Skip to content

Commit

Permalink
Bugfix: canonical url now use current_frontend_locale instead of defa…
Browse files Browse the repository at this point in the history
…ult_frontend_locale

According to google and Yoast: https://yoast.com/rel-canonical/
  • Loading branch information
bricesanchez authored and Brice Sanchez committed Jul 17, 2017
1 parent ffce888 commit 11428f8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
8 changes: 4 additions & 4 deletions pages/app/models/refinery/page.rb
Expand Up @@ -163,15 +163,15 @@ def translated_to_default_locale?

# The canonical page for this particular page.
# Consists of:
# * The default locale's translated slug
# * The current locale's translated slug
def canonical
Globalize.with_locale(::Refinery::I18n.default_frontend_locale) { url }
Globalize.with_locale(::Refinery::I18n.current_frontend_locale) { url }
end

# The canonical slug for this particular page.
# This is the slug for the default frontend locale.
# This is the slug for the current frontend locale.
def canonical_slug
Globalize.with_locale(::Refinery::I18n.default_frontend_locale) { slug }
Globalize.with_locale(::Refinery::I18n.current_frontend_locale) { slug }
end

# Returns in cascading order: custom_slug or menu_title or title depending on
Expand Down
14 changes: 10 additions & 4 deletions pages/spec/models/refinery/page_url_spec.rb
Expand Up @@ -118,12 +118,15 @@ def turn_off_custom_slugs
expect(default_canonical).to eq(page.canonical)
end

specify 'translated page returns master page' do
specify "translated page returns its pages's canonical" do
allow(Refinery::I18n).to receive(:current_frontend_locale).and_return(:ru)

Globalize.with_locale(:ru) do
page.title = ru_page_title
page.save

expect(page.canonical).to eq(default_canonical)
expect(page.canonical).to_not eq(default_canonical)
expect(page.canonical).to eq(page.url)
end
end
end
Expand All @@ -142,12 +145,15 @@ def turn_off_custom_slugs
expect(default_canonical_slug).to eq(page.canonical_slug)
end

specify "translated page returns master page's slug'" do
specify "translated page returns its page's canonical slug'" do
allow(Refinery::I18n).to receive(:current_frontend_locale).and_return(:ru)

Globalize.with_locale(:ru) do
page.title = ru_page_title
page.save

expect(page.canonical_slug).to eq(default_canonical_slug)
expect(page.canonical_slug).to_not eq(default_canonical_slug)
expect(page.canonical_slug).to eq(page.canonical_slug)
end
end
end
Expand Down

0 comments on commit 11428f8

Please sign in to comment.