Skip to content

Commit

Permalink
Merge pull request #243 from kpumuk/mirror-empty-title
Browse files Browse the repository at this point in the history
Fallback to site name when title is empty in mirrored tags
  • Loading branch information
kpumuk authored Sep 15, 2022
2 parents 95b07b5 + 3d40c0d commit aaaa377
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 2.18.0 (September 15, 2022) [](https://github.com/kpumuk/meta-tags/compare/v2.17.0...v2.18.0)

Changes:

- Fallback to site name when title is empty in mirrored tags ([243](https://github.com/kpumuk/meta-tags/pull/243))

## 2.17.0 (July 5, 2022) [](https://github.com/kpumuk/meta-tags/compare/v2.16.0...v2.17.0)

Changes:
Expand Down
6 changes: 4 additions & 2 deletions lib/meta_tags/meta_tags_collection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,16 @@ def full_title(defaults = {})
with_defaults(defaults) { extract_full_title }
end

# Constructs the title without site title (for normalized parameters).
# Constructs the title without site title (for normalized parameters). When title is empty,
# use the site title instead.
#
# @return [String] page title.
#
def page_title(defaults = {})
old_site = @meta_tags[:site]
@meta_tags[:site] = nil
with_defaults(defaults) { extract_full_title }
full_title = with_defaults(defaults) { extract_full_title }
full_title.presence || old_site || ''
ensure
@meta_tags[:site] = old_site
end
Expand Down
2 changes: 1 addition & 1 deletion lib/meta_tags/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

module MetaTags
# Gem version.
VERSION = '2.17.0'
VERSION = '2.18.0'
public_constant :VERSION
end
11 changes: 10 additions & 1 deletion spec/view_helper/open_graph_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
end
end

it "properlies handle title and site title in mirrored content" do
it "properly handle title and site title in mirrored content" do
subject.set_meta_tags(title: 'someTitle', site: 'someSite')
subject.display_meta_tags(open_graph: { title: :title, site_name: :site, full_title: :full_title }).tap do |meta|
expect(meta).to have_tag('meta', with: { content: "someTitle", property: "og:title" })
Expand All @@ -74,6 +74,15 @@
end
end

it "uses site_title for mirrored title, when title is empty" do
subject.set_meta_tags(title: '', site: 'someSite')
subject.display_meta_tags(open_graph: { title: :title, site_name: :site, full_title: :full_title }).tap do |meta|
expect(meta).to have_tag('meta', with: { content: "someSite", property: "og:title" })
expect(meta).to have_tag('meta', with: { content: "someSite", property: "og:site_name" })
expect(meta).to have_tag('meta', with: { content: "someSite", property: "og:full_title" })
end
end

it "displays open graph meta tags with an array of images" do
subject.set_meta_tags(
open_graph: {
Expand Down

0 comments on commit aaaa377

Please sign in to comment.