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 d6bcdff..ec85c6f 100644 --- a/cdmm/app/helpers/application_helper.rb +++ b/cdmm/app/helpers/application_helper.rb @@ -1,4 +1,8 @@ module ApplicationHelper + def custom_title(title) + "#{title} #{default_meta_tags[:separator]} #{default_meta_tags[:site]}" + end + def default_meta_tags { site: 'CDMM', @@ -10,7 +14,7 @@ def default_meta_tags canonical: request.original_url, noindex: !Rails.env.production?, icon: [ - { href: image_url('box.svg'), type: 'image/svg+xml' }, + # { href: image_url('box.svg'), type: 'image/svg+xml' }, # { href: image_url('icon.jpg'), rel: 'apple-touch-icon', sizes: '180x180', type: 'image/jpg' }, ], og: { @@ -19,7 +23,6 @@ def default_meta_tags description: 'The Continuous Delivery Maturity Assessment Form', type: 'website', url: request.original_url, - # image: image_url('login-page.png') } } 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/config/initializers/meta_tags.rb b/cdmm/config/initializers/meta_tags.rb index 752ed4c..74cbfd1 100644 --- a/cdmm/config/initializers/meta_tags.rb +++ b/cdmm/config/initializers/meta_tags.rb @@ -10,7 +10,7 @@ # config.truncate_site_title_first = false # Add HTML attributes to the HTML tag. Default is {}. - # config.title_tag_attributes = {} + config.title_tag_attributes = { id: "page_title" } # Natural separator when truncating. Default is " " (space character). # Set to nil to disable natural separator.