Skip to content

Commit

Permalink
Add canonical meta header
Browse files Browse the repository at this point in the history
  • Loading branch information
jschwindt committed Oct 6, 2023
1 parent c6d414b commit cf08a3c
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 2 deletions.
6 changes: 5 additions & 1 deletion app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ def meta_description(text, og_type = 'website')
@meta_og_type = og_type
end

def canonical_url(url)
@canonical_url = url
end

def alert_message_for(object)
if object.respond_to?(:errors) && object.errors.any?
messages = object.errors.full_messages.map { |msg| content_tag(:li, msg) }.join
Expand Down Expand Up @@ -69,6 +73,6 @@ def month_and_year_select(name, options = {}, html_options = {})
p = {}
end
end
content_tag(:div, class: 'select') { select_month(p[:month].to_i, options, html_options) } +
content_tag(:div, class: 'select') { select_month(p[:month].to_i, options, html_options) } +
content_tag(:div, class: 'select') { select_year(p[:year].to_i, options, html_options) }
end
1 change: 1 addition & 0 deletions app/views/comments/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<% the_title = "Comentario ##{@comment.id} de #{@post.title}" -%>
<% page_title the_title -%>
<% meta_description the_title -%>
<%- canonical_url(post_comment_url(@post, @comment)) %>
<h2 class="title fancy is-4"><%= link_to @post.title, @post %></h2>
<h2 class="title"><%= %"Comentario ##{@comment.id}" %></h2>
<div class="post-show">
Expand Down
1 change: 1 addition & 0 deletions app/views/home/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<%- page_title(nil) %>
<%- canonical_url(root_url) %>
<section>
<h2 class="title fancy is-4">Programas Recientes</h2>
<div class="posts">
Expand Down
3 changes: 2 additions & 1 deletion app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<%= tag 'meta', name: 'twitter:card', content: 'summary' %>
<%= tag 'meta', name: 'twitter:site', content: '@venganzaspasado' %>
<%= tag 'meta', name: 'twitter:creator', content: '@jschwindt' %>
<%= tag 'meta', property: 'og:url', content: request.original_url %>
<%= tag 'meta', property: 'og:url', content: @canonical_url || request.original_url %>
<%= tag 'meta', property: 'og:title', content: yield(:title) %>
<%= 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.' %>
<%= tag 'meta', property: 'og:image', content: asset_url('vdp_logo.jpg') %>
Expand All @@ -18,6 +18,7 @@
<%= tag 'meta', property: 'fb:app_id', content: '39744394508' %>
<%= tag 'meta', property: 'fb:admins', content: 'jschwindt' %>
<%= favicon_link_tag '/favicon.ico' %>
<% if @canonical_url %><link rel="canonical" href="<%= @canonical_url %>" /><% end %>
<link rel="preload" href="<%= asset_path('fas.woff2') %>" as="font" type="font/woff2" crossorigin>
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Didact+Gothic&display=swap">
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png">
Expand Down
3 changes: 3 additions & 0 deletions app/views/posts/archive.html.erb
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
<% if params[:day].present? %>
<% title_part = "Archivo de programas del #{params[:day]}/#{params[:month]}/#{params[:year]}" -%>
<%- canonical_url(posts_archive_url params[:year], params[:month], params[:day]) %>
<% elsif params[:month].present? %>
<% title_part = "Archivo de programas de #{I18n.t('date.month_names')[params[:month].to_i].capitalize} de #{params[:year]}" -%>
<%- canonical_url(posts_archive_url params[:year], params[:month]) %>
<% else -%>
<% title_part = "Archivo de programas del año #{params[:year]}" -%>
<%- canonical_url(posts_archive_url params[:year]) %>
<% end %>
<% if params[:page].nil? %>
<% the_title = title_part %>
Expand Down
2 changes: 2 additions & 0 deletions app/views/posts/contributions.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<% if params[:page].nil? %>
<% the_title = "Contribuciones de Programas de La Venganza será Terrible" -%>
<%- canonical_url(contributions_url) %>
<% else %>
<% the_title = "Contribuciones de Programas de La Venganza será Terrible (página #{params[:page]})" -%>
<%- canonical_url(contributions_url + "/page/" + params[:page]) %>
<% end %>
<% page_title the_title -%>
<% meta_description strip_tags(the_title) -%>
Expand Down
2 changes: 2 additions & 0 deletions app/views/posts/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<% if params[:page].present? %>
<% the_title = "Programas de La Venganza será Terrible de Alejandro Dolina (página #{params[:page]})" -%>
<%- canonical_url(posts_url + "/page/" + params[:page]) %>
<% else %>
<% the_title = "Programas de La Venganza será Terrible de Alejandro Dolina" -%>
<%- canonical_url(posts_url) %>
<% end %>
<% page_title the_title -%>
<% meta_description strip_tags(the_title) -%>
Expand Down
1 change: 1 addition & 0 deletions app/views/posts/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<% page_title @post.title + " - Página #{params[:page]} de comentarios" -%>
<% end %>
<% meta_description @post.description, 'article' -%>
<%- canonical_url(post_url @post) %>
<div class="level is-mobile">
<% if prev_post = @post.previous %>
<div class="level-left">
Expand Down
2 changes: 2 additions & 0 deletions app/views/users/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<% if params[:page].nil? %>
<% the_title = "Perfil de #{@user.alias}" -%>
<%- canonical_url(user_url @user) %>
<% else %>
<% the_title = "Perfil de #{@user.alias} - Página #{params[:page]} de comentarios" -%>
<%- canonical_url(comments_user_path(@user) + "/page/" + params[:page]) %>
<% end %>
<% page_title the_title -%>
<% meta_description the_title + " en Venganzas del Pasado", 'profile' -%>
Expand Down

0 comments on commit cf08a3c

Please sign in to comment.