bridgetown-seo-tag 4.0.1 → 5.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: abb7aa6ad690aea0cc55f5e18a9dd7be9c1461f4b6d7b57977abfc568ae0f09d
4
- data.tar.gz: 27388ed583fc7d3cce45d5eab085bf87d5a30320192a844a97541bb71fbf28da
3
+ metadata.gz: 700724012209f996a9aafe12a6fea52c050e39e0f6afba904e6ea41c5205f6dd
4
+ data.tar.gz: 383ad71d2b5dd8923f40bc8c5e01d7f437ebbce97b3c80d0c84847c2c1895d8a
5
5
  SHA512:
6
- metadata.gz: faa21316c33fd7e2bf19228dcc848b147b5b40ba03f1d12da9229b9b7f665fd9f0b5279198fa43644a67fe67374d2554d61cdb5def9ee12a5d1ad3b8a2f6d420
7
- data.tar.gz: e95daef1af9a8447ac7248fc39b6b9246910150995073b4f8b61160cbf60ac07e48fd3cf721be13310e28eb3cb53d4a1624ea323a0e5d191c6221a509b3758b9
6
+ metadata.gz: 31d8e25501780ce3b73f9b8d9abfff7efa8ddfe1b0f547627742d606458483f454e029b30c1c2cf7cea1040633f347f569198cfdd40dcafd516e3ba0c999395c
7
+ data.tar.gz: cdf16c8875a8b632cc59707fa251a1428f8b64e51871eac6db143615b681f98d8b935e8749edd1d41f02e15dd36bd8c830682d3114890b00b55bbdc1da0fb5c9
data/.rubocop.yml CHANGED
@@ -17,3 +17,10 @@ Layout/LineLength:
17
17
  Metrics/BlockLength:
18
18
  Exclude:
19
19
  - spec/**/*
20
+
21
+ Lint/MissingSuper:
22
+ Enabled: false
23
+
24
+ Performance/CollectionLiteralInLoop:
25
+ Exclude:
26
+ - spec/**/*
data/CHANGELOG.md CHANGED
@@ -1,31 +1,37 @@
1
1
  # Changelog
2
2
 
3
+ ## 5.0.0 / 2021-10-17
4
+
5
+ - Change "Site Title | Site Tagline" format to "Site Title: Site Tagline"
6
+ - also handle Bridgetown 1.0 templates where the homepage title defaults to `Index`
7
+ - upgrade rubocop-bridgetown gem to 0.3
8
+
3
9
  ## 4.0.1 / 2021-06-04
4
10
 
5
- * Fix bug where resources' relative URLs weren't included properly
11
+ - Fix bug where resources' relative URLs weren't included properly
6
12
 
7
13
  ## 4.0.0 / 2021-04-17
8
14
 
9
- * New release with helper to support Ruby templates like ERB
15
+ - New release with helper to support Ruby templates like ERB
10
16
 
11
17
  ## 3.0.5 / 2020-06-18
12
18
 
13
- * Final release
19
+ - Final release
14
20
 
15
21
  ## 3.0.5.beta1 / 2020-05-31
16
22
 
17
- * Fix bugs due to Bridgetown 0.15 switch to `render` tag.
18
- * Switch to using Rubocop Bridgetown gem.
23
+ - Fix bugs due to Bridgetown 0.15 switch to `render` tag.
24
+ - Switch to using Rubocop Bridgetown gem.
19
25
 
20
26
  ## 3.0.4 / 2020-05-01
21
27
 
22
- Update to require a minimum Ruby version of 2.5.
28
+ - Update to require a minimum Ruby version of 2.5.
23
29
 
24
30
  ## 3.0.3 / 2020-04-19
25
31
 
26
- Allow `site.metadata.twitter` data if present. Look for `page.subtitle` if
32
+ - Allow `site.metadata.twitter` data if present. Look for `page.subtitle` if
27
33
  `page.description` isn't present.
28
34
 
29
35
  ## 3.0.0 / 2020-04-14
30
36
 
31
- Use Bridgetown gem and rename to bridgetown-seo-tag.
37
+ - Use Bridgetown gem and rename to bridgetown-seo-tag.
@@ -22,5 +22,5 @@ Gem::Specification.new do |spec|
22
22
  spec.add_development_dependency "html-proofer", "~> 3.7"
23
23
  spec.add_development_dependency "rake", "~> 12.0"
24
24
  spec.add_development_dependency "rspec", "~> 3.5"
25
- spec.add_development_dependency "rubocop-bridgetown", "~> 0.2"
25
+ spec.add_development_dependency "rubocop-bridgetown", "~> 0.3"
26
26
  end
@@ -41,8 +41,7 @@ module Bridgetown
41
41
 
42
42
  private
43
43
 
44
- attr_reader :page
45
- attr_reader :site
44
+ attr_reader :page, :site
46
45
 
47
46
  # Finds the page author in the page.author, page.authors, or site.author
48
47
  #
@@ -62,10 +61,9 @@ module Bridgetown
62
61
  # Returns a hash representing additional metadata or an empty hash
63
62
  def site_data_hash
64
63
  @site_data_hash ||= begin
65
- return {} unless resolved_author.is_a?(String)
66
- return {} unless site.data["authors"].is_a?(Hash)
67
-
68
- author_hash = site.data["authors"][resolved_author]
64
+ author_hash = if site.data.authors.is_a?(Hash) && resolved_author.is_a?(String)
65
+ site.data.authors[resolved_author]
66
+ end
69
67
  author_hash.is_a?(Hash) ? author_hash : {}
70
68
  end
71
69
  end
@@ -74,15 +72,14 @@ module Bridgetown
74
72
  # including site-wide metadata if the author is provided as a string,
75
73
  # or an empty hash, if the author cannot be resolved
76
74
  def author_hash
77
- @author_hash ||= begin
78
- if resolved_author.is_a? Hash
79
- resolved_author
80
- elsif resolved_author.is_a? String
81
- { "name" => resolved_author }.merge(site_data_hash)
82
- else
83
- {}
84
- end
85
- end
75
+ @author_hash ||= case resolved_author
76
+ when Hash
77
+ resolved_author
78
+ when String
79
+ { "name" => resolved_author }.merge(site_data_hash)
80
+ else
81
+ {}
82
+ end
86
83
  end
87
84
 
88
85
  # Since author_hash is aliased to fallback_data, any values in the hash
@@ -6,6 +6,7 @@ module Bridgetown
6
6
  include Bridgetown::SeoTag::UrlHelper
7
7
 
8
8
  TITLE_SEPARATOR = " | "
9
+ TAGLINE_SEPARATOR = ": "
9
10
  FORMAT_STRING_METHODS = [
10
11
  :markdownify, :strip_html, :normalize_whitespace, :escape_once,
11
12
  ].freeze
@@ -47,7 +48,14 @@ module Bridgetown
47
48
 
48
49
  # Page title without site title or description appended
49
50
  def page_title
50
- @page_title ||= format_string(page["title"]) || site_title
51
+ @page_title ||= format_string(
52
+ if (page["title"] == "Index" || page["title"].blank?) &&
53
+ site_tagline_or_description
54
+ "#{site_title}#{TAGLINE_SEPARATOR}#{site_tagline_or_description}"
55
+ else
56
+ page["title"]
57
+ end
58
+ ) || site_title
51
59
  end
52
60
 
53
61
  def site_tagline_or_description
@@ -55,23 +63,18 @@ module Bridgetown
55
63
  end
56
64
 
57
65
  # Page title with site title or description appended
58
- # rubocop:disable Metrics/CyclomaticComplexity
59
66
  def title
60
- @title ||= begin
61
- if site_title && page_title != site_title
62
- page_title + TITLE_SEPARATOR + site_title
63
- elsif site_description && site_title
64
- site_title + TITLE_SEPARATOR + site_tagline_or_description
65
- else
66
- page_title || site_title
67
- end
68
- end
67
+ @title ||= if site_title && page_title != site_title &&
68
+ !format_string(page_title).start_with?(site_title + TAGLINE_SEPARATOR)
69
+ page_title + TITLE_SEPARATOR + site_title
70
+ else
71
+ page_title || site_title
72
+ end
69
73
 
70
74
  return page_number + @title if page_number
71
75
 
72
76
  @title
73
77
  end
74
- # rubocop:enable Metrics/CyclomaticComplexity
75
78
 
76
79
  def name
77
80
  return @name if defined?(@name)
@@ -88,11 +91,9 @@ module Bridgetown
88
91
  end
89
92
 
90
93
  def description
91
- @description ||= begin
92
- format_string(
93
- page["description"] || page["subtitle"] || page["excerpt"]
94
- ) || site_description
95
- end
94
+ @description ||= format_string(
95
+ page["description"] || page["subtitle"] || page["excerpt"]
96
+ ) || site_description
96
97
  end
97
98
 
98
99
  # A drop representing the page author
@@ -125,39 +126,33 @@ module Bridgetown
125
126
  end
126
127
 
127
128
  def type
128
- @type ||= begin
129
- if page_seo["type"]
130
- page_seo["type"]
131
- elsif homepage_or_about?
132
- "WebSite"
133
- elsif page["date"]
134
- "BlogPosting"
135
- else
136
- "WebPage"
137
- end
138
- end
129
+ @type ||= if page_seo["type"]
130
+ page_seo["type"]
131
+ elsif homepage_or_about?
132
+ "WebSite"
133
+ elsif page["date"]
134
+ "BlogPosting"
135
+ else
136
+ "WebPage"
137
+ end
139
138
  end
140
139
 
141
140
  def links
142
- @links ||= begin
143
- if page_seo["links"]
144
- page_seo["links"]
145
- elsif homepage_or_about? && site_social["links"]
146
- site_social["links"]
147
- end
148
- end
141
+ @links ||= if page_seo["links"]
142
+ page_seo["links"]
143
+ elsif homepage_or_about? && site_social["links"]
144
+ site_social["links"]
145
+ end
149
146
  end
150
147
 
151
148
  def logo
152
- @logo ||= begin
153
- return unless site.data.dig("site_metadata", "logo")
154
-
155
- if absolute_url? site.data.dig("site_metadata", "logo")
156
- filters.uri_escape site.data.dig("site_metadata", "logo")
157
- else
158
- filters.uri_escape filters.absolute_url site.data.dig("site_metadata", "logo")
159
- end
160
- end
149
+ @logo ||= if !site.data.dig("site_metadata", "logo")
150
+ nil
151
+ elsif absolute_url? site.data.dig("site_metadata", "logo")
152
+ filters.uri_escape site.data.dig("site_metadata", "logo")
153
+ else
154
+ filters.uri_escape filters.absolute_url site.data.dig("site_metadata", "logo")
155
+ end
161
156
  end
162
157
 
163
158
  def page_lang
@@ -165,15 +160,15 @@ module Bridgetown
165
160
  end
166
161
 
167
162
  def canonical_url
168
- @canonical_url ||= begin
169
- if page["canonical_url"].to_s.present?
170
- page["canonical_url"]
171
- elsif page["url"].to_s.present?
172
- filters.absolute_url(page["url"]).to_s.gsub(%r!/index\.html$!, "/")
173
- else
174
- filters.absolute_url(page["relative_url"]).to_s.gsub(%r!/index\.html$!, "/")
175
- end
176
- end
163
+ @canonical_url ||= if page["canonical_url"].to_s.present?
164
+ page["canonical_url"]
165
+ elsif page["url"].to_s.present?
166
+ filters.absolute_url(page["url"]).to_s.gsub(%r!/index\.html$!, "/")
167
+ else
168
+ filters.absolute_url(page["relative_url"]).to_s.gsub(
169
+ %r!/index\.html$!, "/"
170
+ )
171
+ end
177
172
  end
178
173
 
179
174
  private
@@ -227,7 +222,7 @@ module Bridgetown
227
222
  end
228
223
 
229
224
  def site_social
230
- @site_social ||= sub_hash(site.data.dig("site_metadata"), "social")
225
+ @site_social ||= sub_hash(site.data["site_metadata"], "social")
231
226
  end
232
227
 
233
228
  # Safely returns a sub hash
@@ -34,14 +34,14 @@ module Bridgetown
34
34
 
35
35
  private
36
36
 
37
- attr_accessor :page
38
- attr_accessor :context
37
+ attr_accessor :page, :context
39
38
 
40
39
  # The normalized image hash with a `path` key (which may be nil)
41
40
  def image_hash
42
- @image_hash ||= if page["image"].is_a?(Hash)
41
+ @image_hash ||= case page["image"]
42
+ when Hash
43
43
  { "path" => nil }.merge(page["image"])
44
- elsif page["image"].is_a?(String)
44
+ when String
45
45
  { "path" => page["image"] }
46
46
  else
47
47
  { "path" => nil }
@@ -50,9 +50,7 @@ module Bridgetown
50
50
  alias_method :fallback_data, :image_hash
51
51
 
52
52
  def raw_path
53
- @raw_path ||= begin
54
- image_hash["path"] || image_hash["facebook"] || image_hash["twitter"]
55
- end
53
+ @raw_path ||= image_hash["path"] || image_hash["facebook"] || image_hash["twitter"]
56
54
  end
57
55
 
58
56
  def absolute_url
@@ -1,10 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Prevent bundler errors
4
- module Liquid; class Tag; end; end
4
+ module Liquid; class Tag; end; end # rubocop:disable Lint/EmptyClass
5
5
 
6
6
  module Bridgetown
7
7
  class SeoTag < Liquid::Tag
8
- VERSION = "4.0.1"
8
+ VERSION = "5.0.0"
9
9
  end
10
10
  end
@@ -81,15 +81,11 @@ module Bridgetown
81
81
  private
82
82
 
83
83
  def template_contents
84
- @template_contents ||= begin
85
- File.read(template_path).gsub(MINIFY_REGEX, "")
86
- end
84
+ @template_contents ||= File.read(template_path).gsub(MINIFY_REGEX, "")
87
85
  end
88
86
 
89
87
  def template_path
90
- @template_path ||= begin
91
- File.expand_path "./template.html", File.dirname(__FILE__)
92
- end
88
+ @template_path ||= File.expand_path "./template.html", File.dirname(__FILE__)
93
89
  end
94
90
  end
95
91
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bridgetown-seo-tag
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.1
4
+ version: 5.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bridgetown Team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-06-04 00:00:00.000000000 Z
11
+ date: 2021-10-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bridgetown
@@ -92,14 +92,14 @@ dependencies:
92
92
  requirements:
93
93
  - - "~>"
94
94
  - !ruby/object:Gem::Version
95
- version: '0.2'
95
+ version: '0.3'
96
96
  type: :development
97
97
  prerelease: false
98
98
  version_requirements: !ruby/object:Gem::Requirement
99
99
  requirements:
100
100
  - - "~>"
101
101
  - !ruby/object:Gem::Version
102
- version: '0.2'
102
+ version: '0.3'
103
103
  description:
104
104
  email: maintainers@bridgetownrb.com
105
105
  executables: []
@@ -144,7 +144,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
144
144
  - !ruby/object:Gem::Version
145
145
  version: '0'
146
146
  requirements: []
147
- rubygems_version: 3.1.2
147
+ rubygems_version: 3.1.4
148
148
  signing_key:
149
149
  specification_version: 4
150
150
  summary: A Bridgetown plugin to add metadata tags for search engines and social networks