From a37d26f5592b6b384bea08643001ba89c65fc7e7 Mon Sep 17 00:00:00 2001 From: Jean Date: Mon, 22 Jan 2024 13:57:52 -0400 Subject: [PATCH] FEATURE: Add support for custom site name in Open Graph metadata (#25373) --- app/helpers/application_helper.rb | 2 +- spec/helpers/application_helper_spec.rb | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index b9c3f0680fd..b644a289475 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -301,7 +301,7 @@ module ApplicationHelper ) if opts[:twitter_summary_large_image].present? result = [] - result << tag(:meta, property: "og:site_name", content: SiteSetting.title) + result << tag(:meta, property: "og:site_name", content: opts[:site_name] || SiteSetting.title) result << tag(:meta, property: "og:type", content: "website") generate_twitter_card_metadata(result, opts) diff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rb index 74bd9b17049..2ad6caa7ee3 100644 --- a/spec/helpers/application_helper_spec.rb +++ b/spec/helpers/application_helper_spec.rb @@ -687,6 +687,27 @@ RSpec.describe ApplicationHelper do expect(metadata).to include output_tags end end + + context "with custom site name" do + before { SiteSetting.title = "Default Site Title" } + + it "uses the provided site name in og:site_name" do + custom_site_name = "Custom Site Name" + result = helper.crawlable_meta_data(site_name: custom_site_name) + + expect(result).to include( + "", + ) + end + + it "falls back to the default site title if no custom site name is provided" do + result = helper.crawlable_meta_data + + expect(result).to include( + "", + ) + end + end end describe "discourse_color_scheme_stylesheets" do