Add HTML customization to admin (#20531)

* Add HTML customization to admin

* Update spec/requests/stories_index_spec.rb

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
This commit is contained in:
Ben Halpern 2024-01-17 07:12:22 -05:00 committed by GitHub
parent 5c2723a04e
commit 16ff57c2ff
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 54 additions and 0 deletions

View file

@ -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

View file

@ -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

View file

@ -115,6 +115,22 @@
</p>
</div>
</div>
<div class="crayons-field">
<%= 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] %>
</div>
<div class="crayons-field">
<%= 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] %>
</div>
</fieldset>
<%= render "update_setting_button", f: f %>
</div>

View file

@ -43,6 +43,7 @@
<meta property="forem:logo" content="<%= optimized_image_url(Settings::General.logo_png, width: 512, fetch_format: "png") %>" />
<meta property="forem:domain" content="<%= Settings::General.app_domain %>" />
<% end %>
<%= Settings::UserExperience.head_content.html_safe %>
</head>
<% unless internal_navigation? %>
<% cache(release_adjusted_cache_key("top-html-and-config--#{user_signed_in?}")) do %>
@ -114,6 +115,7 @@
<% end %>
<div id="i18n-translations" data-translations="<%= { I18n.locale.to_sym => { core: I18n::JS.translations[I18n.locale.to_sym][:core] } }.to_json %>"></div>
<%= render "articles/reaction_category_resources" %>
<%= Settings::UserExperience.bottom_of_body_content.html_safe %>
</body>
</html>
<% end %>

View file

@ -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.'

View file

@ -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.'

View file

@ -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)