bridgetown-seo-tag 4.0.1 → 6.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: f52feeb06f0b0cc5bc8a893251e22db438727808592d79027c2069a2c36c05ef
4
+ data.tar.gz: 68a1b3dce65f5b959de19d2da22611be530cc4ab9fed9bc366e7d052eadbd2ba
5
5
  SHA512:
6
- metadata.gz: faa21316c33fd7e2bf19228dcc848b147b5b40ba03f1d12da9229b9b7f665fd9f0b5279198fa43644a67fe67374d2554d61cdb5def9ee12a5d1ad3b8a2f6d420
7
- data.tar.gz: e95daef1af9a8447ac7248fc39b6b9246910150995073b4f8b61160cbf60ac07e48fd3cf721be13310e28eb3cb53d4a1624ea323a0e5d191c6221a509b3758b9
6
+ metadata.gz: 2251e9c40bb873fd729e7e74b7f8124a911d85a79ea7f0d9ebd0ad1088cfbee3ebba23c6149a648a37bec38208b8318999e0afc3f0e722470d8540f515204b5c
7
+ data.tar.gz: c1620483b79ac3cc063fd595d42b64f5dc4faa96cbcc78c59243d6d62577f6c8537c59da83d093c58b15bca90987a7043f35b69d01bf4a141ce7d75ee54ad462
data/.rubocop.yml CHANGED
@@ -5,7 +5,7 @@ inherit_gem:
5
5
  rubocop-bridgetown: .rubocop.yml
6
6
 
7
7
  AllCops:
8
- TargetRubyVersion: 2.5
8
+ TargetRubyVersion: 2.7
9
9
  Exclude:
10
10
  - vendor/**/*
11
11
 
@@ -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,44 @@
1
1
  # Changelog
2
2
 
3
+ ## 6.0.0 / 2023-01-08
4
+
5
+ - Fix bug where prev/next rel links for paginated pages were missing
6
+ - Upgrade to initializers system in Bridgetown 1.2
7
+ - Add support for image alt metadata
8
+ - Add fallback for og:type metadata
9
+
10
+ ## 5.0.0 / 2021-10-17
11
+
12
+ - Change "Site Title | Site Tagline" format to "Site Title: Site Tagline"
13
+ - also handle Bridgetown 1.0 templates where the homepage title defaults to `Index`
14
+ - upgrade rubocop-bridgetown gem to 0.3
15
+
3
16
  ## 4.0.1 / 2021-06-04
4
17
 
5
- * Fix bug where resources' relative URLs weren't included properly
18
+ - Fix bug where resources' relative URLs weren't included properly
6
19
 
7
20
  ## 4.0.0 / 2021-04-17
8
21
 
9
- * New release with helper to support Ruby templates like ERB
22
+ - New release with helper to support Ruby templates like ERB
10
23
 
11
24
  ## 3.0.5 / 2020-06-18
12
25
 
13
- * Final release
26
+ - Final release
14
27
 
15
28
  ## 3.0.5.beta1 / 2020-05-31
16
29
 
17
- * Fix bugs due to Bridgetown 0.15 switch to `render` tag.
18
- * Switch to using Rubocop Bridgetown gem.
30
+ - Fix bugs due to Bridgetown 0.15 switch to `render` tag.
31
+ - Switch to using Rubocop Bridgetown gem.
19
32
 
20
33
  ## 3.0.4 / 2020-05-01
21
34
 
22
- Update to require a minimum Ruby version of 2.5.
35
+ - Update to require a minimum Ruby version of 2.5.
23
36
 
24
37
  ## 3.0.3 / 2020-04-19
25
38
 
26
- Allow `site.metadata.twitter` data if present. Look for `page.subtitle` if
39
+ - Allow `site.metadata.twitter` data if present. Look for `page.subtitle` if
27
40
  `page.description` isn't present.
28
41
 
29
42
  ## 3.0.0 / 2020-04-14
30
43
 
31
- Use Bridgetown gem and rename to bridgetown-seo-tag.
44
+ - Use Bridgetown gem and rename to bridgetown-seo-tag.
@@ -11,16 +11,17 @@ Gem::Specification.new do |spec|
11
11
  spec.homepage = "https://github.com/bridgetownrb/bridgetown-seo-tag"
12
12
  spec.license = "MIT"
13
13
 
14
- spec.required_ruby_version = ">= 2.5.0"
14
+ spec.required_ruby_version = ">= 2.7.0"
15
15
 
16
16
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r!^(test|script|spec|features)/!) }
17
17
  spec.require_paths = ["lib"]
18
18
 
19
- spec.add_dependency "bridgetown", ">= 0.20.0", "< 2.0"
19
+ spec.add_dependency "bridgetown", ">= 1.2.0.beta5", "< 2.0"
20
20
 
21
21
  spec.add_development_dependency "bundler", ">= 1.15"
22
22
  spec.add_development_dependency "html-proofer", "~> 3.7"
23
- spec.add_development_dependency "rake", "~> 12.0"
23
+ spec.add_development_dependency "rake", "~> 13.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
+ spec.metadata["rubygems_mfa_required"] = "true"
26
27
  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
@@ -4,8 +4,8 @@ module Bridgetown
4
4
  class SeoTag
5
5
  class Builder < Bridgetown::Builder
6
6
  def build
7
- helper "seo", helpers_scope: true do |title: true|
8
- context = Liquid::Context.new({}, {}, { site: site, page: view.page })
7
+ helper "seo" do |title: true|
8
+ context = Liquid::Context.new({}, {}, { site: site, page: helpers.view.page })
9
9
  tag_output = Liquid::Template.parse(
10
10
  "{% seo #{"title=false" unless title} %}"
11
11
  ).render!(context, {})
@@ -15,5 +15,3 @@ module Bridgetown
15
15
  end
16
16
  end
17
17
  end
18
-
19
- Bridgetown::SeoTag::Builder.register
@@ -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 = "6.0.0"
9
9
  end
10
10
  end
@@ -44,7 +44,9 @@ module Bridgetown
44
44
  end
45
45
 
46
46
  def payload
47
- paginator = context.registers[:page].pager if context.registers[:page].respond_to?(:pager)
47
+ if context.registers[:page].respond_to?(:paginator)
48
+ paginator = context.registers[:page].paginator
49
+ end
48
50
 
49
51
  # site_payload is an instance of UnifiedPayloadDrop
50
52
  Bridgetown::Utils.deep_merge_hashes(
@@ -81,20 +83,19 @@ module Bridgetown
81
83
  private
82
84
 
83
85
  def template_contents
84
- @template_contents ||= begin
85
- File.read(template_path).gsub(MINIFY_REGEX, "")
86
- end
86
+ @template_contents ||= File.read(template_path).gsub(MINIFY_REGEX, "")
87
87
  end
88
88
 
89
89
  def template_path
90
- @template_path ||= begin
91
- File.expand_path "./template.html", File.dirname(__FILE__)
92
- end
90
+ @template_path ||= File.expand_path "./template.html", File.dirname(__FILE__)
93
91
  end
94
92
  end
95
93
  end
96
94
  end
97
95
 
98
96
  Liquid::Template.register_tag("seo", Bridgetown::SeoTag)
99
-
100
97
  require "bridgetown-seo-tag/builder"
98
+
99
+ Bridgetown.initializer :"bridgetown-seo-tag" do |config|
100
+ config.builder Bridgetown::SeoTag::Builder
101
+ end
data/lib/template.html CHANGED
@@ -35,11 +35,16 @@
35
35
  {% if seo_tag.image.width %}
36
36
  <meta property="og:image:width" content="{{ seo_tag.image.width }}" />
37
37
  {% endif %}
38
+ {% if seo_tag.image.alt %}
39
+ <meta property="og:image:alt" content="{{ seo_tag.image.alt }}" />
40
+ {% endif %}
38
41
  {% endif %}
39
42
 
40
43
  {% if page.date %}
41
44
  <meta property="og:type" content="article" />
42
45
  <meta property="article:published_time" content="{{ page.date | date_to_xmlschema }}" />
46
+ {% else %}
47
+ <meta property="og:type" content="website" />
43
48
  {% endif %}
44
49
 
45
50
  {% if paginator.previous_page %}
@@ -49,7 +54,6 @@
49
54
  <link rel="next" href="{{ paginator.next_page_path | absolute_url }}" />
50
55
  {% endif %}
51
56
 
52
-
53
57
  {% if seo_tag.image %}
54
58
  <meta name="twitter:card" content="{{ page.twitter.card | default: site.metadata.twitter.card | default: "summary_large_image" }}" />
55
59
  <meta property="twitter:image" content="{{ seo_tag.image.path }}" />
@@ -57,6 +61,10 @@
57
61
  <meta name="twitter:card" content="summary" />
58
62
  {% endif %}
59
63
 
64
+ {% if seo_tag.image.alt %}
65
+ <meta name="twitter:image:alt" content="{{ seo_tag.image.alt }}" />
66
+ {% endif %}
67
+
60
68
  {% if seo_tag.page_title %}
61
69
  <meta property="twitter:title" content="{{ seo_tag.page_title }}" />
62
70
  {% endif %}
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: 6.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bridgetown Team
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-06-04 00:00:00.000000000 Z
11
+ date: 2023-01-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bridgetown
@@ -16,7 +16,7 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 0.20.0
19
+ version: 1.2.0.beta5
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
22
  version: '2.0'
@@ -26,7 +26,7 @@ dependencies:
26
26
  requirements:
27
27
  - - ">="
28
28
  - !ruby/object:Gem::Version
29
- version: 0.20.0
29
+ version: 1.2.0.beta5
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
32
  version: '2.0'
@@ -64,14 +64,14 @@ dependencies:
64
64
  requirements:
65
65
  - - "~>"
66
66
  - !ruby/object:Gem::Version
67
- version: '12.0'
67
+ version: '13.0'
68
68
  type: :development
69
69
  prerelease: false
70
70
  version_requirements: !ruby/object:Gem::Requirement
71
71
  requirements:
72
72
  - - "~>"
73
73
  - !ruby/object:Gem::Version
74
- version: '12.0'
74
+ version: '13.0'
75
75
  - !ruby/object:Gem::Dependency
76
76
  name: rspec
77
77
  requirement: !ruby/object:Gem::Requirement
@@ -92,15 +92,15 @@ 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'
103
- description:
102
+ version: '0.3'
103
+ description:
104
104
  email: maintainers@bridgetownrb.com
105
105
  executables: []
106
106
  extensions: []
@@ -128,8 +128,9 @@ files:
128
128
  homepage: https://github.com/bridgetownrb/bridgetown-seo-tag
129
129
  licenses:
130
130
  - MIT
131
- metadata: {}
132
- post_install_message:
131
+ metadata:
132
+ rubygems_mfa_required: 'true'
133
+ post_install_message:
133
134
  rdoc_options: []
134
135
  require_paths:
135
136
  - lib
@@ -137,15 +138,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
137
138
  requirements:
138
139
  - - ">="
139
140
  - !ruby/object:Gem::Version
140
- version: 2.5.0
141
+ version: 2.7.0
141
142
  required_rubygems_version: !ruby/object:Gem::Requirement
142
143
  requirements:
143
144
  - - ">="
144
145
  - !ruby/object:Gem::Version
145
146
  version: '0'
146
147
  requirements: []
147
- rubygems_version: 3.1.2
148
- signing_key:
148
+ rubygems_version: 3.3.3
149
+ signing_key:
149
150
  specification_version: 4
150
151
  summary: A Bridgetown plugin to add metadata tags for search engines and social networks
151
152
  to better index and display your site's content.