FEATURE: Add support for custom site name in Open Graph metadata (#25373)

This commit is contained in:
Jean 2024-01-22 13:57:52 -04:00 committed by GitHub
parent 93264da206
commit a37d26f559
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 22 additions and 1 deletions

View File

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

View File

@ -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(
"<meta property=\"og:site_name\" content=\"#{custom_site_name}\" />",
)
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(
"<meta property=\"og:site_name\" content=\"#{SiteSetting.title}\" />",
)
end
end
end
describe "discourse_color_scheme_stylesheets" do