Add community_emoji to SiteConfig (#11450)
* Add optional community_emoji to SiteConfig * Remove hardcoded emojis, favor community_emoji instead * Remove remaining hardcoded emojis * Validate community_emoji field when updated
This commit is contained in:
parent
449cf89737
commit
59ea42a372
10 changed files with 59 additions and 8 deletions
|
|
@ -14,6 +14,7 @@ module Admin
|
|||
COMMUNITY_PARAMS =
|
||||
%i[
|
||||
community_name
|
||||
community_emoji
|
||||
collective_noun
|
||||
collective_noun_disabled
|
||||
community_description
|
||||
|
|
@ -127,6 +128,7 @@ module Admin
|
|||
display_email_domain_allow_list_publicly
|
||||
].freeze
|
||||
|
||||
EMOJI_ONLY_FIELDS = %w[community_emoji].freeze
|
||||
IMAGE_FIELDS =
|
||||
%w[
|
||||
main_social_image
|
||||
|
|
@ -146,6 +148,7 @@ module Admin
|
|||
|
||||
before_action :extra_authorization_and_confirmation, only: [:create]
|
||||
before_action :validate_inputs, only: [:create]
|
||||
before_action :validate_emoji, only: [:create], if: -> { params[:site_config].keys & EMOJI_ONLY_FIELDS }
|
||||
before_action :validate_image_urls, only: [:create], if: -> { params[:site_config].keys & IMAGE_FIELDS }
|
||||
after_action :bust_content_change_caches, only: [:create]
|
||||
|
||||
|
|
@ -217,6 +220,15 @@ module Admin
|
|||
redirect_to admin_config_path, alert: "😭 #{errors.to_sentence}" if errors.any?
|
||||
end
|
||||
|
||||
def validate_emoji
|
||||
emoji_params = config_params.slice(*EMOJI_ONLY_FIELDS).to_h
|
||||
errors = emoji_params.filter_map do |field, value|
|
||||
non_emoji_characters = value.downcase.gsub(EmojiRegex::RGIEmoji, "")
|
||||
"#{field} contains invalid emoji" if non_emoji_characters.present?
|
||||
end
|
||||
redirect_to admin_config_path, alert: "😭 #{errors.to_sentence}" if errors.any?
|
||||
end
|
||||
|
||||
def validate_image_urls
|
||||
image_params = config_params.slice(*IMAGE_FIELDS).to_h
|
||||
errors = image_params.filter_map do |field, url|
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ module ApplicationHelper
|
|||
derived_title = if page_title.include?(community_name)
|
||||
page_title
|
||||
elsif user_signed_in?
|
||||
"#{page_title} - #{community_qualified_name} 👩💻👨💻"
|
||||
"#{page_title} - #{community_qualified_name} #{community_emoji}"
|
||||
else
|
||||
"#{page_title} - #{community_name}"
|
||||
end
|
||||
|
|
@ -185,6 +185,10 @@ module ApplicationHelper
|
|||
@community_name ||= SiteConfig.community_name
|
||||
end
|
||||
|
||||
def community_emoji
|
||||
@community_emoji ||= SiteConfig.community_emoji
|
||||
end
|
||||
|
||||
def community_qualified_name
|
||||
return "#{community_name} #{SiteConfig.collective_noun}" unless SiteConfig.collective_noun_disabled
|
||||
|
||||
|
|
|
|||
|
|
@ -57,6 +57,10 @@ module Constants
|
|||
description: "Used in meta description tags etc.",
|
||||
placeholder: "A fabulous community of kind and welcoming people."
|
||||
},
|
||||
community_emoji: {
|
||||
description: "Used in the title tags across the site alongside the community name",
|
||||
placeholder: ""
|
||||
},
|
||||
community_member_label: {
|
||||
description: "Used to determine what a member will be called e.g developer, hobbyist etc.",
|
||||
placeholder: "user"
|
||||
|
|
|
|||
|
|
@ -50,6 +50,7 @@ class SiteConfig < RailsSettings::Base
|
|||
|
||||
# Community Content
|
||||
field :community_name, type: :string, default: ApplicationConfig["COMMUNITY_NAME"] || "New Forem"
|
||||
field :community_emoji, type: :string, default: "🌱"
|
||||
field :collective_noun, type: :string, default: "Community"
|
||||
field :collective_noun_disabled, type: :boolean, default: false
|
||||
field :community_description, type: :string
|
||||
|
|
|
|||
|
|
@ -443,6 +443,15 @@
|
|||
<%= f.check_box :collective_noun_disabled, checked: SiteConfig.collective_noun_disabled, data: { action: "config#disableTargetField", disable_target: "collectiveNoun" }, class: "crayons-checkbox" %>
|
||||
</div>
|
||||
|
||||
<div class="crayons-field">
|
||||
<%= admin_config_label :community_emoji %>
|
||||
<%= admin_config_description Constants::SiteConfig::DETAILS[:community_emoji][:description] %>
|
||||
<%= f.text_field :community_emoji,
|
||||
class: "crayons-textfield",
|
||||
value: SiteConfig.community_emoji,
|
||||
placeholder: Constants::SiteConfig::DETAILS[:community_emoji][:placeholder] %>
|
||||
</div>
|
||||
|
||||
<div class="crayons-field">
|
||||
<%= admin_config_label :tagline %>
|
||||
<%= admin_config_description Constants::SiteConfig::DETAILS[:tagline][:description] %>
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
<%= content_for :page_meta do %>
|
||||
<% title_with_timeframe(
|
||||
page_title: "#{community_qualified_name} 👩💻👨💻",
|
||||
page_title: "#{community_qualified_name} #{community_emoji}",
|
||||
timeframe: params[:timeframe],
|
||||
content_for: true,
|
||||
) %>
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
<% title("#{community_name} Connect 👩💻💬👨💻") %>
|
||||
<% title("#{community_name} Connect") %>
|
||||
<%= content_for :page_meta do %>
|
||||
<link rel="canonical" href="<%= app_url(connect_path) %>" />
|
||||
<meta name="description" content="<%= community_name %> Connect">
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ require "rails_helper"
|
|||
RSpec.describe TweetTag, type: :liquid_tag do
|
||||
let(:twitter_id) { "1018911886862057472" }
|
||||
let(:handle) { "thepracticaldev" }
|
||||
let(:name) { "DEV Community 👩💻👨💻" }
|
||||
let(:name) { "DEV Community" }
|
||||
let(:body) { "When GitHub goes down" }
|
||||
|
||||
setup { Liquid::Template.register_tag("tweet", described_class) }
|
||||
|
|
|
|||
|
|
@ -144,6 +144,23 @@ RSpec.describe "/admin/config", type: :request do
|
|||
expect(SiteConfig.community_description).to eq(description)
|
||||
end
|
||||
|
||||
it "updates the community_emoji if valid" do
|
||||
allow(SiteConfig).to receive(:community_emoji).and_call_original
|
||||
emoji = "🥐"
|
||||
post "/admin/config", params: { site_config: { community_emoji: emoji },
|
||||
confirmation: confirmation_message }
|
||||
expect(SiteConfig.community_emoji).to eq(emoji)
|
||||
end
|
||||
|
||||
it "does not update the community_emoji if invalid" do
|
||||
allow(SiteConfig).to receive(:community_emoji).and_call_original
|
||||
not_an_emoji = "i love croissants"
|
||||
expect do
|
||||
post "/admin/config", params: { site_config: { community_emoji: not_an_emoji },
|
||||
confirmation: confirmation_message }
|
||||
end.not_to change(SiteConfig, :community_emoji)
|
||||
end
|
||||
|
||||
it "updates the community_name" do
|
||||
name_magoo = "Hey hey #{rand(100)}"
|
||||
post "/admin/config", params: { site_config: { community_name: name_magoo },
|
||||
|
|
|
|||
|
|
@ -21,11 +21,13 @@ RSpec.describe "StoriesShow", type: :request do
|
|||
|
||||
## Title tag
|
||||
it "renders signed-in title tag for signed-in user" do
|
||||
allow(SiteConfig).to receive(:community_emoji).and_return("🌱")
|
||||
|
||||
sign_in user
|
||||
get article.path
|
||||
|
||||
expected_title = "<title>#{CGI.escapeHTML(article.title)} - #{community_qualified_name} 👩💻👨💻</title>"
|
||||
expect(response.body).to include(expected_title)
|
||||
title = "<title>#{CGI.escapeHTML(article.title)} - #{community_qualified_name} #{community_emoji}</title>"
|
||||
expect(response.body).to include(title)
|
||||
end
|
||||
|
||||
it "renders signed-out title tag for signed-out user" do
|
||||
|
|
@ -44,12 +46,14 @@ RSpec.describe "StoriesShow", type: :request do
|
|||
end
|
||||
|
||||
it "does not render title tag with search_optimized_title_preamble if set and not signed in" do
|
||||
allow(SiteConfig).to receive(:community_emoji).and_return("🌱")
|
||||
|
||||
sign_in user
|
||||
article.update_column(:search_optimized_title_preamble, "Hey this is a test")
|
||||
get article.path
|
||||
|
||||
expected_title = "<title>#{CGI.escapeHTML(article.title)} - #{community_qualified_name} 👩💻👨💻</title>"
|
||||
expect(response.body).to include(expected_title)
|
||||
title = "<title>#{CGI.escapeHTML(article.title)} - #{community_qualified_name} #{community_emoji}</title>"
|
||||
expect(response.body).to include(title)
|
||||
end
|
||||
|
||||
it "does not render preamble with search_optimized_title_preamble not signed in but not set" do
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue