Skip to content

Commit

Permalink
Use pages url path in page preview for external sites
Browse files Browse the repository at this point in the history
If the page preview renders an external site instead of the internal one we pass the url-path instead of the urlname so we make sure that root page urls are ` /` and the language code is prefixed.
  • Loading branch information
tvdeyen committed Jun 11, 2020
1 parent 5795da2 commit 102d9c1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/alchemy/admin/preview_url.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def url_for(page)
if @preview_config && uri
uri_class.build(
host: uri.host,
path: "/#{page.urlname}",
path: page.url_path,
userinfo: userinfo,
).to_s
else
Expand Down
14 changes: 14 additions & 0 deletions spec/libraries/admin/preview_url_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,20 @@
end
end
end

context "with page being the language root page" do
let(:page) { create(:alchemy_page, :language_root) }

before do
stub_alchemy_config(:preview, {
"host" => "https://www.example.com",
})
end

it "returns the preview url without urlname" do
is_expected.to eq "https://www.example.com/"
end
end
end
end
end

0 comments on commit 102d9c1

Please sign in to comment.