From ca44c134554585ac4fe5dfa301f82697224ded9d Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Sat, 8 Apr 2017 06:15:40 -0400 Subject: [PATCH] Use Setting.site_title value for `og:site_name` occurrences (#1194) * Add helper method to return Setting.site_title * Use site_title helper in application layout * Use site_title value for og:site_name --- app/helpers/site_title_helper.rb | 7 +++++++ app/views/about/index.html.haml | 2 +- app/views/accounts/show.html.haml | 2 +- app/views/layouts/application.html.haml | 2 +- app/views/stream_entries/show.html.haml | 2 +- spec/helpers/site_title_helper_spec.rb | 15 +++++++++++++++ 6 files changed, 26 insertions(+), 4 deletions(-) create mode 100644 app/helpers/site_title_helper.rb create mode 100644 spec/helpers/site_title_helper_spec.rb diff --git a/app/helpers/site_title_helper.rb b/app/helpers/site_title_helper.rb new file mode 100644 index 0000000000..d2caa92038 --- /dev/null +++ b/app/helpers/site_title_helper.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +module SiteTitleHelper + def site_title + Setting.site_title.to_s + end +end diff --git a/app/views/about/index.html.haml b/app/views/about/index.html.haml index ebca4213a7..f6b0c16685 100644 --- a/app/views/about/index.html.haml +++ b/app/views/about/index.html.haml @@ -5,7 +5,7 @@ = Rails.configuration.x.local_domain - content_for :header_tags do - %meta{ property: 'og:site_name', content: 'Mastodon' }/ + %meta{ property: 'og:site_name', content: site_title }/ %meta{ property: 'og:type', content: 'website' }/ %meta{ property: 'og:title', content: Rails.configuration.x.local_domain }/ %meta{ property: 'og:description', content: @description.blank? ? "Mastodon is a free, open-source social network server. A decentralized alternative to commercial platforms, it avoids the risks of a single company monopolizing your communication. Anyone can run Mastodon and participate in the social network seamlessly" : strip_tags(@description) }/ diff --git a/app/views/accounts/show.html.haml b/app/views/accounts/show.html.haml index 3b8c67b459..e90897729f 100644 --- a/app/views/accounts/show.html.haml +++ b/app/views/accounts/show.html.haml @@ -5,7 +5,7 @@ %link{ rel: 'salmon', href: api_salmon_url(@account.id) }/ %link{ rel: 'alternate', type: 'application/atom+xml', href: account_url(@account, format: 'atom') }/ - %meta{ property: 'og:site_name', content: 'Mastodon' }/ + %meta{ property: 'og:site_name', content: site_title }/ %meta{ property: 'og:type', content: 'profile' }/ %meta{ property: 'og:title', content: "#{@account.username} on #{Rails.configuration.x.local_domain}" }/ %meta{ property: 'og:description', content: @account.note }/ diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index abab14a287..e8253bd6f9 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -15,7 +15,7 @@ - if content_for?(:page_title) = yield(:page_title) = ' - ' - = Setting.site_title + = site_title = stylesheet_link_tag 'application', media: 'all' = csrf_meta_tags diff --git a/app/views/stream_entries/show.html.haml b/app/views/stream_entries/show.html.haml index c109ff4b84..088881b11f 100644 --- a/app/views/stream_entries/show.html.haml +++ b/app/views/stream_entries/show.html.haml @@ -2,7 +2,7 @@ %link{ rel: 'alternate', type: 'application/atom+xml', href: account_stream_entry_url(@account, @stream_entry, format: 'atom') }/ %link{ rel: 'alternate', type: 'application/json+oembed', href: api_oembed_url(url: account_stream_entry_url(@account, @stream_entry), format: 'json') }/ - %meta{ property: 'og:site_name', content: 'Mastodon' }/ + %meta{ property: 'og:site_name', content: site_title }/ %meta{ property: 'og:type', content: 'article' }/ %meta{ property: 'og:title', content: "#{@account.username} on #{Rails.configuration.x.local_domain}" }/ diff --git a/spec/helpers/site_title_helper_spec.rb b/spec/helpers/site_title_helper_spec.rb new file mode 100644 index 0000000000..8cfd9cba1c --- /dev/null +++ b/spec/helpers/site_title_helper_spec.rb @@ -0,0 +1,15 @@ +require "rails_helper" + +describe "site_title" do + it "Uses the Setting.site_title value when it exists" do + Setting.site_title = "New site title" + + expect(helper.site_title).to eq "New site title" + end + + it "returns empty string when Setting.site_title is nil" do + Setting.site_title = nil + + expect(helper.site_title).to eq "" + end +end