diff --git a/cdmm/Gemfile b/cdmm/Gemfile
index 21f4172..2d100ee 100644
--- a/cdmm/Gemfile
+++ b/cdmm/Gemfile
@@ -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"
diff --git a/cdmm/Gemfile.lock b/cdmm/Gemfile.lock
index d632e7f..257cdc2 100644
--- a/cdmm/Gemfile.lock
+++ b/cdmm/Gemfile.lock
@@ -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)
@@ -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
diff --git a/cdmm/app/controllers/cdmm_controller.rb b/cdmm/app/controllers/cdmm_controller.rb
index 0011fde..51d19c1 100644
--- a/cdmm/app/controllers/cdmm_controller.rb
+++ b/cdmm/app/controllers/cdmm_controller.rb
@@ -1,4 +1,5 @@
class CdmmController < ApplicationController
+ include ApplicationHelper
# Viewing
# if form_key is empty, it will create a draft version and show the default data
# if form_key is in the database, it will populate data and show them
@@ -53,6 +54,7 @@ def save()
ev.form_status = :published
if ev.save
@table = evaluation_table(ev, form_key)
+ new_page_title = "
#{custom_title(ev[:title])}"
respond_to do |format|
format.turbo_stream {
render turbo_stream: [
@@ -64,12 +66,14 @@ def save()
.replace("evaluation_form_title",
partial: "form_title",
locals: { text: @table[:title] }),
+ turbo_stream
+ .replace("page_title", new_page_title)
]
}
format.html {
redirect_to evaluation_show_path(ev.form_key), notice: 'Evaluation was successfully created.'
}
- end
+ end
else
# Handle errors (e.g., re-render the form with errors)
render_internal_server_error
diff --git a/cdmm/app/helpers/application_helper.rb b/cdmm/app/helpers/application_helper.rb
index de6be79..ec85c6f 100644
--- a/cdmm/app/helpers/application_helper.rb
+++ b/cdmm/app/helpers/application_helper.rb
@@ -1,2 +1,29 @@
module ApplicationHelper
+ def custom_title(title)
+ "#{title} #{default_meta_tags[:separator]} #{default_meta_tags[:site]}"
+ end
+
+ 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,
+ }
+ }
+ end
end
diff --git a/cdmm/app/views/cdmm/show.html.erb b/cdmm/app/views/cdmm/show.html.erb
index 430addf..c954360 100644
--- a/cdmm/app/views/cdmm/show.html.erb
+++ b/cdmm/app/views/cdmm/show.html.erb
@@ -1,3 +1,14 @@
+<%
+ set_meta_tags(
+ title: @table[:title],
+ description: @table[:title],
+ og: {
+ title: @table[:title],
+ description: @table[:title]
+ }
+ )
+%>
+
<%= render "cdmm_form", table: @table %>
\ No newline at end of file
diff --git a/cdmm/app/views/layouts/application.html.erb b/cdmm/app/views/layouts/application.html.erb
index 70199c1..bfead44 100644
--- a/cdmm/app/views/layouts/application.html.erb
+++ b/cdmm/app/views/layouts/application.html.erb
@@ -1,6 +1,7 @@
+ <%= display_meta_tags default_meta_tags %>
<%= content_for(:title) || "CDMM" %>
diff --git a/cdmm/config/initializers/meta_tags.rb b/cdmm/config/initializers/meta_tags.rb
new file mode 100644
index 0000000..74cbfd1
--- /dev/null
+++ b/cdmm/config/initializers/meta_tags.rb
@@ -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 HTML tag. Default is {}.
+ config.title_tag_attributes = { id: "page_title" }
+
+ # 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 () instead
+ # of open (``). Default is true.
+ # config.open_meta_tags = true
+
+ # List of additional meta tags that should use "property" attribute instead
+ # of "name" attribute in tags.
+ # config.property_tags.push(
+ # 'x-hearthstone:deck',
+ # )
+end