Add canonical url to posts even if internal nav (#5227) [deploy]
* Add canonical url to posts even if internal nav * Render to meta if not internal
This commit is contained in:
parent
2312d2e301
commit
7a867d6133
2 changed files with 16 additions and 6 deletions
|
|
@ -36,13 +36,11 @@
|
|||
<% end %>
|
||||
<% end %>
|
||||
|
||||
<% if !internal_navigation? %>
|
||||
<% if internal_navigation? %>
|
||||
<link rel="canonical" href="<%= @article.canonical_url.presence || "https://#{ApplicationConfig['APP_DOMAIN']}#{@article.path}" %>" />
|
||||
<% else %>
|
||||
<%= content_for :page_meta do %>
|
||||
<% if @article.canonical_url.present? %>
|
||||
<link rel="canonical" href="<%= @article.canonical_url %>" />
|
||||
<% else %>
|
||||
<link rel="canonical" href="https://dev.to<%= @article.path %>" />
|
||||
<% end %>
|
||||
<link rel="canonical" href="<%= @article.canonical_url.presence || "https://#{ApplicationConfig['APP_DOMAIN']}#{@article.path}" %>" />
|
||||
<meta name="description" content="<%= @article.description || "An article from the community" %>">
|
||||
<meta name="keywords" content="software development, inclusive, community, engineering, <%= @article.cached_tag_list %>">
|
||||
|
||||
|
|
|
|||
|
|
@ -107,6 +107,18 @@ RSpec.describe "StoriesShow", type: :request do
|
|||
get "/#{middle_username}/#{article.slug}"
|
||||
expect(response.body).to redirect_to("/#{user.username}/#{article.slug}")
|
||||
end
|
||||
|
||||
it "renders canonical url when exists" do
|
||||
article = create(:article, with_canonical_url: true)
|
||||
get article.path
|
||||
expect(response.body).to include('"canonical" href="' + article.canonical_url.to_s + '"')
|
||||
end
|
||||
|
||||
it "shodoes not render canonical url when not on article model" do
|
||||
article = create(:article, with_canonical_url: false)
|
||||
get article.path
|
||||
expect(response.body).not_to include('"canonical" href="' + article.canonical_url.to_s + '"')
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET /:username (org)" do
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue