Skip to content

Commit

Permalink
feat: Add custom meta tags
Browse files Browse the repository at this point in the history
  • Loading branch information
chonla committed Oct 23, 2024
1 parent 963e930 commit 654c4b3
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 0 deletions.
2 changes: 2 additions & 0 deletions cdmm/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ gem "tzinfo-data", platforms: %i[ windows jruby ]
# Reduces boot times through caching; required in config/boot.rb
gem "bootsnap", require: false

gem "meta-tags"

# Use Active Storage variants [https://guides.rubyonrails.org/active_storage_overview.html#transforming-images]
# gem "image_processing", "~> 1.2"

Expand Down
3 changes: 3 additions & 0 deletions cdmm/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ GEM
net-smtp
marcel (1.0.4)
matrix (0.4.2)
meta-tags (2.22.1)
actionpack (>= 6.0.0, < 8.1)
mini_mime (1.1.5)
minitest (5.25.1)
msgpack (1.7.3)
Expand Down Expand Up @@ -341,6 +343,7 @@ DEPENDENCIES
debug
importmap-rails
jbuilder
meta-tags
puma (>= 5.0)
rails (~> 7.2.1, >= 7.2.1.1)
rails_live_reload
Expand Down
24 changes: 24 additions & 0 deletions cdmm/app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,26 @@
module ApplicationHelper
def default_meta_tags
{
site: 'CDMM',
title: 'Continuous Delivery Maturity Model',
reverse: true,
separator: '|',
description: 'Continuous Delivery Maturity Assessment Form',
keywords: 'action, horror, drama',
canonical: request.original_url,
noindex: !Rails.env.production?,
icon: [
{ href: image_url('box.svg'), type: 'image/svg+xml' },
# { href: image_url('icon.jpg'), rel: 'apple-touch-icon', sizes: '180x180', type: 'image/jpg' },
],
og: {
site_name: 'CDMM',
title: 'Continuous Delivery Maturity Model',
description: 'The Continuous Delivery Maturity Assessment Form',
type: 'website',
url: request.original_url,
# image: image_url('login-page.png')
}
}
end
end
1 change: 1 addition & 0 deletions cdmm/app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<!DOCTYPE html>
<html>
<head>
<%= display_meta_tags default_meta_tags %>
<title><%= content_for(:title) || "CDMM" %></title>
<meta name="viewport" content="width=device-width,initial-scale=1">
<meta name="mobile-web-app-capable" content="yes">
Expand Down
49 changes: 49 additions & 0 deletions cdmm/config/initializers/meta_tags.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# frozen_string_literal: true

# Use this setup block to configure all options available in MetaTags.
MetaTags.configure do |config|
# How many characters should the title meta tag have at most. Default is 70.
# Set to nil or 0 to remove limits.
# config.title_limit = 70

# When true, site title will be truncated instead of title. Default is false.
# config.truncate_site_title_first = false

# Add HTML attributes to the <title> HTML tag. Default is {}.
# config.title_tag_attributes = {}

# Natural separator when truncating. Default is " " (space character).
# Set to nil to disable natural separator.
# This also allows you to use a whitespace regular expression (/\s/) or
# a Unicode space (/\p{Space}/).
# config.truncate_on_natural_separator = " "

# Maximum length of the page description. Default is 300.
# Set to nil or 0 to remove limits.
# config.description_limit = 300

# Maximum length of the keywords meta tag. Default is 255.
# config.keywords_limit = 255

# Default separator for keywords meta tag (used when an Array passed with
# the list of keywords). Default is ", ".
# config.keywords_separator = ', '

# When true, keywords will be converted to lowercase, otherwise they will
# appear on the page as is. Default is true.
# config.keywords_lowercase = true

# When true, the output will not include new line characters between meta tags.
# Default is false.
# config.minify_output = false

# When false, generated meta tags will be self-closing (<meta ... />) instead
# of open (`<meta ...>`). Default is true.
# config.open_meta_tags = true

# List of additional meta tags that should use "property" attribute instead
# of "name" attribute in <meta> tags.
# config.property_tags.push(
# 'x-hearthstone:deck',
# )
end

0 comments on commit 654c4b3

Please sign in to comment.