Skip to content

Commit e1f999e

Browse files
committed
Improve SEO and page titles
1 parent 16dd577 commit e1f999e

File tree

10 files changed

+36
-2
lines changed

10 files changed

+36
-2
lines changed

app/controllers/concerns/alpha_indexable.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ module AlphaIndexable
88
def set_alpha_index
99
@has_alpha_index = true
1010
@letter = params[:letter] || default_alpha_index
11+
@page_title = "#{@title} Index: #{@letter.upcase}" if @letter.present?
1112
set_alpha_index_collection
1213
end
1314

app/controllers/concerns/searchable.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ module Searchable
77

88
def load_search_query
99
@search = params[:q]
10+
@page_description = "#{@title} Search Results for '#{h @search}'"
1011
@exact_match = @collection.dup.where("lower(name) = ?", @search.downcase).first
1112
@collection = @collection.where("lower(name) LIKE ? AND lower(name) != ?", "%#{@search.downcase}%", @search.downcase)
1213
end

app/controllers/featured_controller.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ class FeaturedController < ApplicationController
44

55
prepend_before_action do
66
@title = "Featured Libraries"
7+
@page_title = @title
78
@collection = featured_libraries
89
end
910

app/controllers/stdlib_controller.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ class StdlibController < ApplicationController
33

44
prepend_before_action do
55
@title = "Ruby Standard Library"
6+
@page_title = @title
67
@collection = Library.stdlib.all
78
end
89

app/helpers/application_helper.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,18 @@ def settings
3030
Rubydoc.config
3131
end
3232

33+
def page_title
34+
"#{settings.name}: #{title_content}"
35+
end
36+
37+
def title_content
38+
@page_title || content_for(:title) || page_description
39+
end
40+
41+
def page_description
42+
@page_description || content_for(:description) || settings.description
43+
end
44+
3345
def link_to_library(library, version = nil)
3446
prefix = case library.source
3547
when :featured

app/views/layouts/application.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<!DOCTYPE html>
22
<html>
33
<head>
4-
<title><%= content_for(:title) || Rubydoc.config.name %></title>
4+
<%= render "shared/meta" %>
55
<%= csrf_meta_tags %>
66
<%= csp_meta_tag %>
77
<%= yield :head %>

app/views/shared/_meta.html.erb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<title><%= h page_title %></title>
2+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
3+
<meta name="description" content="<%= h page_description %>" />
4+
<% if @search %>
5+
<meta name="robots" content="noindex, nofollow">
6+
<% else %>
7+
<meta name="robots" content="index, follow">
8+
<% end %>
9+
<link rel="canonical" href="<%= request.original_url %>">
10+
<meta property="og:title" content="<%= h page_title %>">
11+
<meta property="og:description" content="<%= h page_description %>">
12+
<meta property="og:image" content="<%= URI(request.original_url).tap { it.path = "/favicon.ico" }.to_s %>">
13+
<meta property="og:url" content="<%= request.original_url %>">
14+
<meta property="og:type" content="website">

app/views/shared/library_list.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
</div>
66
<% end %>
77
<h2>
8-
<%= @title %> <%= h @search ? "Search Results for '#{@search}'" : 'Listing' %>
8+
<%= h @search ? @page_description : "#{@title} Listing" %>
99
<% if @search %>
1010
<span class="small">(<%= link_to "Back to Listing", controller: controller_name %>)</span>
1111
<% end %>

config/initializers/rubydoc.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ def self.config; @config; end
55
def self.config=(config)
66
@config = JSON.parse({
77
name: "RubyDoc.info",
8+
description: "Documenting RubyGems, Stdlib, and GitHub Projects",
89
integrations: {
910
rubygems: Rails.application.credentials.rubydoc&.rubygems_api_key,
1011
cloudflare_token: Rails.application.credentials.rubydoc&.cloudflare_token,

config/rubydoc.yml.sample

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ default: &default
33
# Display title. Defaults to RubyDoc.info
44
# name: RubyDoc.info
55

6+
# Default page description
7+
# description: Documenting RubyGems, Stdlib, and GitHub Projects
8+
69
gem_hosting:
710
# If you want to enable or disable gem hosting, set the following to true or false
811
# enabled: true

0 commit comments

Comments
 (0)