Skip to content

Commit cf08a3c

Browse files
committed
Add canonical meta header
1 parent c6d414b commit cf08a3c

File tree

9 files changed

+19
-2
lines changed

9 files changed

+19
-2
lines changed

app/helpers/application_helper.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ def meta_description(text, og_type = 'website')
1616
@meta_og_type = og_type
1717
end
1818

19+
def canonical_url(url)
20+
@canonical_url = url
21+
end
22+
1923
def alert_message_for(object)
2024
if object.respond_to?(:errors) && object.errors.any?
2125
messages = object.errors.full_messages.map { |msg| content_tag(:li, msg) }.join
@@ -69,6 +73,6 @@ def month_and_year_select(name, options = {}, html_options = {})
6973
p = {}
7074
end
7175
end
72-
content_tag(:div, class: 'select') { select_month(p[:month].to_i, options, html_options) } +
76+
content_tag(:div, class: 'select') { select_month(p[:month].to_i, options, html_options) } +
7377
content_tag(:div, class: 'select') { select_year(p[:year].to_i, options, html_options) }
7478
end

app/views/comments/show.html.erb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<% the_title = "Comentario ##{@comment.id} de #{@post.title}" -%>
22
<% page_title the_title -%>
33
<% meta_description the_title -%>
4+
<%- canonical_url(post_comment_url(@post, @comment)) %>
45
<h2 class="title fancy is-4"><%= link_to @post.title, @post %></h2>
56
<h2 class="title"><%= %"Comentario ##{@comment.id}" %></h2>
67
<div class="post-show">

app/views/home/index.html.erb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<%- page_title(nil) %>
2+
<%- canonical_url(root_url) %>
23
<section>
34
<h2 class="title fancy is-4">Programas Recientes</h2>
45
<div class="posts">

app/views/layouts/application.html.erb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<%= tag 'meta', name: 'twitter:card', content: 'summary' %>
1010
<%= tag 'meta', name: 'twitter:site', content: '@venganzaspasado' %>
1111
<%= tag 'meta', name: 'twitter:creator', content: '@jschwindt' %>
12-
<%= tag 'meta', property: 'og:url', content: request.original_url %>
12+
<%= tag 'meta', property: 'og:url', content: @canonical_url || request.original_url %>
1313
<%= tag 'meta', property: 'og:title', content: yield(:title) %>
1414
<%= tag 'meta', property: 'og:description', content: @meta_description || 'El sitio donde podés escuchar online y descargar los archivos de audio en MP3 del programa La Venganza será Terrible de Alejandro Dolina.' %>
1515
<%= tag 'meta', property: 'og:image', content: asset_url('vdp_logo.jpg') %>
@@ -18,6 +18,7 @@
1818
<%= tag 'meta', property: 'fb:app_id', content: '39744394508' %>
1919
<%= tag 'meta', property: 'fb:admins', content: 'jschwindt' %>
2020
<%= favicon_link_tag '/favicon.ico' %>
21+
<% if @canonical_url %><link rel="canonical" href="<%= @canonical_url %>" /><% end %>
2122
<link rel="preload" href="<%= asset_path('fas.woff2') %>" as="font" type="font/woff2" crossorigin>
2223
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Didact+Gothic&display=swap">
2324
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png">

app/views/posts/archive.html.erb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
<% if params[:day].present? %>
22
<% title_part = "Archivo de programas del #{params[:day]}/#{params[:month]}/#{params[:year]}" -%>
3+
<%- canonical_url(posts_archive_url params[:year], params[:month], params[:day]) %>
34
<% elsif params[:month].present? %>
45
<% title_part = "Archivo de programas de #{I18n.t('date.month_names')[params[:month].to_i].capitalize} de #{params[:year]}" -%>
6+
<%- canonical_url(posts_archive_url params[:year], params[:month]) %>
57
<% else -%>
68
<% title_part = "Archivo de programas del año #{params[:year]}" -%>
9+
<%- canonical_url(posts_archive_url params[:year]) %>
710
<% end %>
811
<% if params[:page].nil? %>
912
<% the_title = title_part %>

app/views/posts/contributions.html.erb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
<% if params[:page].nil? %>
22
<% the_title = "Contribuciones de Programas de La Venganza será Terrible" -%>
3+
<%- canonical_url(contributions_url) %>
34
<% else %>
45
<% the_title = "Contribuciones de Programas de La Venganza será Terrible (página #{params[:page]})" -%>
6+
<%- canonical_url(contributions_url + "/page/" + params[:page]) %>
57
<% end %>
68
<% page_title the_title -%>
79
<% meta_description strip_tags(the_title) -%>

app/views/posts/index.html.erb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
<% if params[:page].present? %>
22
<% the_title = "Programas de La Venganza será Terrible de Alejandro Dolina (página #{params[:page]})" -%>
3+
<%- canonical_url(posts_url + "/page/" + params[:page]) %>
34
<% else %>
45
<% the_title = "Programas de La Venganza será Terrible de Alejandro Dolina" -%>
6+
<%- canonical_url(posts_url) %>
57
<% end %>
68
<% page_title the_title -%>
79
<% meta_description strip_tags(the_title) -%>

app/views/posts/show.html.erb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<% page_title @post.title + " - Página #{params[:page]} de comentarios" -%>
55
<% end %>
66
<% meta_description @post.description, 'article' -%>
7+
<%- canonical_url(post_url @post) %>
78
<div class="level is-mobile">
89
<% if prev_post = @post.previous %>
910
<div class="level-left">

app/views/users/show.html.erb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
<% if params[:page].nil? %>
22
<% the_title = "Perfil de #{@user.alias}" -%>
3+
<%- canonical_url(user_url @user) %>
34
<% else %>
45
<% the_title = "Perfil de #{@user.alias} - Página #{params[:page]} de comentarios" -%>
6+
<%- canonical_url(comments_user_path(@user) + "/page/" + params[:page]) %>
57
<% end %>
68
<% page_title the_title -%>
79
<% meta_description the_title + " en Venganzas del Pasado", 'profile' -%>

0 commit comments

Comments
 (0)