diff --git a/app/lib/constants/settings/user_experience.rb b/app/lib/constants/settings/user_experience.rb index 6d381281f..ee04adb2b 100644 --- a/app/lib/constants/settings/user_experience.rb +++ b/app/lib/constants/settings/user_experience.rb @@ -44,6 +44,14 @@ module Constants tag_feed_minimum_score: { description: I18n.t("lib.constants.settings.user_experience.tag_feed.description"), placeholder: "0" + }, + head_content: { + description: I18n.t("lib.constants.settings.user_experience.head_content.description"), + placeholder: I18n.t("lib.constants.settings.user_experience.head_content.placeholder") + }, + bottom_of_body_content: { + description: I18n.t("lib.constants.settings.user_experience.bottom_of_body_content.description"), + placeholder: I18n.t("lib.constants.settings.user_experience.bottom_of_body_content.placeholder") } } end diff --git a/app/models/settings/user_experience.rb b/app/models/settings/user_experience.rb index 50612582c..a04a994dc 100644 --- a/app/models/settings/user_experience.rb +++ b/app/models/settings/user_experience.rb @@ -41,5 +41,9 @@ module Settings setting :default_locale, type: :string, default: "en" setting :display_in_directory, type: :boolean, default: true setting :award_tag_minimum_score, type: :integer, default: 100 + + # Head and footer content + setting :head_content, type: :string, default: "" + setting :bottom_of_body_content, type: :string, default: "" end end diff --git a/app/views/admin/settings/forms/_user_experience.html.erb b/app/views/admin/settings/forms/_user_experience.html.erb index a12c9c5e6..cb8c1ab53 100644 --- a/app/views/admin/settings/forms/_user_experience.html.erb +++ b/app/views/admin/settings/forms/_user_experience.html.erb @@ -115,6 +115,22 @@

+
+ <%= admin_config_label :head_content, model: Settings::UserExperience %> + <%= admin_config_description Constants::Settings::UserExperience.details[:head_content][:description] %> + <%= f.text_area :head_content, + class: "crayons-textfield", + value: Settings::UserExperience.head_content, + placeholder: Constants::Settings::UserExperience.details[:head_content][:placeholder] %> +
+
+ <%= admin_config_label :bottom_of_body_content, model: Settings::UserExperience %> + <%= admin_config_description Constants::Settings::UserExperience.details[:bottom_of_body_content][:description] %> + <%= f.text_area :bottom_of_body_content, + class: "crayons-textfield", + value: Settings::UserExperience.bottom_of_body_content, + placeholder: Constants::Settings::UserExperience.details[:bottom_of_body_content][:placeholder] %> +
<%= render "update_setting_button", f: f %> diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index e0b72bca9..1d7f21575 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -43,6 +43,7 @@ " /> <% end %> + <%= Settings::UserExperience.head_content.html_safe %> <% unless internal_navigation? %> <% cache(release_adjusted_cache_key("top-html-and-config--#{user_signed_in?}")) do %> @@ -114,6 +115,7 @@ <% end %>
<%= render "articles/reaction_category_resources" %> + <%= Settings::UserExperience.bottom_of_body_content.html_safe %> <% end %> diff --git a/config/locales/lib/en.yml b/config/locales/lib/en.yml index 298c607fe..ba15dd825 100644 --- a/config/locales/lib/en.yml +++ b/config/locales/lib/en.yml @@ -226,3 +226,9 @@ en: description: Determines background/border of buttons etc. Must be dark enough to contrast with white text. tag_feed: description: Minimum score needed for a post to show up on default tag page. + head_content: + description: Content that will be appended to the bottom of the head tag on every page (WARNING — This will cache within the page request unevenly. Proceed with care). + placeholder: 'Leave empty if you do not want to add anything.' + bottom_of_body_content: + description: Content that will be appended to the bottom of the body tag on every page (WARNING — This will cache within the page request unevenly. Proceed with care). + placeholder: 'Leave empty if you do not want to add anything.' diff --git a/config/locales/lib/fr.yml b/config/locales/lib/fr.yml index 4e00556cc..111255394 100644 --- a/config/locales/lib/fr.yml +++ b/config/locales/lib/fr.yml @@ -226,3 +226,9 @@ fr: description: Determines background/border of buttons etc. Must be dark enough to contrast with white text. tag_feed: description: Minimum score needed for a post to show up on default tag page. + head_content: + description: Content that will be appended to the bottom of the head tag on every page (WARNING — This will cache within the page request unevenly. Proceed with care). + placeholder: 'Leave empty if you do not want to add anything.' + bottom_of_body_content: + description: Content that will be appended to the bottom of the body tag on every page (WARNING — This will cache within the page request unevenly. Proceed with care). + placeholder: 'Leave empty if you do not want to add anything.' diff --git a/spec/requests/stories_index_spec.rb b/spec/requests/stories_index_spec.rb index a229f81b4..4e4851682 100644 --- a/spec/requests/stories_index_spec.rb +++ b/spec/requests/stories_index_spec.rb @@ -15,6 +15,18 @@ RSpec.describe "StoriesIndex" do let(:user) { create(:user) } let(:org) { create(:organization) } + it "renders head content if present" do + allow(Settings::UserExperience).to receive(:head_content).and_return("head content") + get "/" + expect(response.body).to include("head content") + end + + it "renders bottom of body content if present" do + allow(Settings::UserExperience).to receive(:bottom_of_body_content).and_return("bottom of body content") + get "/" + expect(response.body).to include("bottom of body content") + end + it "renders page with article list and proper attributes", :aggregate_failures do article = create(:article, featured: true) navigation_link = create(:navigation_link)