meta-tags 2.18.0 → 2.22.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/CHANGELOG.md +48 -3
- data/README.md +208 -232
- data/certs/kpumuk.pem +19 -18
- data/lib/generators/meta_tags/install_generator.rb +1 -1
- data/lib/generators/meta_tags/templates/config/initializers/meta_tags.rb +9 -0
- data/lib/meta-tags.rb +1 -1
- data/lib/meta_tags/configuration.rb +24 -16
- data/lib/meta_tags/controller_helper.rb +3 -3
- data/lib/meta_tags/meta_tags_collection.rb +22 -22
- data/lib/meta_tags/railtie.rb +4 -4
- data/lib/meta_tags/renderer.rb +33 -29
- data/lib/meta_tags/text_normalizer.rb +20 -22
- data/lib/meta_tags/version.rb +1 -1
- data/lib/meta_tags/view_helper.rb +2 -2
- data/lib/meta_tags.rb +12 -12
- data/sig/lib/_internal/rails.rbs +3 -0
- data/sig/lib/meta_tags/configuration.rbs +7 -0
- data/sig/lib/meta_tags/controller_helper.rbs +1 -0
- data/sig/lib/meta_tags/text_normalizer.rbs +2 -2
- data/sig/lib/meta_tags/view_helper.rbs +2 -0
- data/sig/lib/meta_tags.rbs +2 -0
- data.tar.gz.sig +0 -0
- metadata +134 -39
- metadata.gz.sig +0 -0
- data/Gemfile +0 -30
- data/Rakefile +0 -49
- data/Steepfile +0 -15
- data/meta-tags.gemspec +0 -43
data/certs/kpumuk.pem
CHANGED
@@ -1,20 +1,21 @@
|
|
1
1
|
-----BEGIN CERTIFICATE-----
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
2
|
+
MIIDcDCCAligAwIBAgIBATANBgkqhkiG9w0BAQsFADA/MQ8wDQYDVQQDDAZrcHVt
|
3
|
+
dWsxFjAUBgoJkiaJk/IsZAEZFgZrcHVtdWsxFDASBgoJkiaJk/IsZAEZFgRpbmZv
|
4
|
+
MB4XDTI0MDcxNTIxMzIyNFoXDTI1MDcxNTIxMzIyNFowPzEPMA0GA1UEAwwGa3B1
|
5
|
+
bXVrMRYwFAYKCZImiZPyLGQBGRYGa3B1bXVrMRQwEgYKCZImiZPyLGQBGRYEaW5m
|
6
|
+
bzCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBALw2YroZc+IT+rs8NuPu
|
7
|
+
c13DelrxrpAgPEu1zuRb3l7WaHRNWA4TyS8Z6Aa1G2O+FdUZNMW1n7IwP/QMJ9Mz
|
8
|
+
ahRBiTmhik5kasJ9s0h1lq5/hZiycm0o5OtGioUzCkvk+UEMpzMHbLmVSZCzYciy
|
9
|
+
NDRDbXB0rLLu1eJk+gKgn6Qf5vj93h1w28BdWdaA7YegtbmipZ+pjmzCQAfPActT
|
10
|
+
6uXHG4dSo7Lz9jiFRI5dUizFbGXcRqkQ2b5AB8FFmfcvbqERvzQKBICnybjsKP0N
|
11
|
+
pJ3vGgO2sh5GvJFOPk1Vlur2nX9ZFznPEP1CEAQ+NFrmKRt355Z5sgOkAojSGnIL
|
12
|
+
/1sCAwEAAaN3MHUwCQYDVR0TBAIwADALBgNVHQ8EBAMCBLAwHQYDVR0OBBYEFPa4
|
13
|
+
VFc1YOlV1u/7EGTwMCAk8YE9MB0GA1UdEQQWMBSBEmtwdW11a0BrcHVtdWsuaW5m
|
14
|
+
bzAdBgNVHRIEFjAUgRJrcHVtdWtAa3B1bXVrLmluZm8wDQYJKoZIhvcNAQELBQAD
|
15
|
+
ggEBADXj54X1y7Pw0Wp5wdniZE13a8EwWC41BEIsSoBLkGQhZ2OOR+5tVUM9kCwG
|
16
|
+
kX6YdliORLuLevYXKiXFluiETwKTeAd6zUURy7eLlwQ1GvhE8wmGk0TQY11v8FMj
|
17
|
+
7AupDtulpP01gLDZwbysovu/3btfhrLVncJ2zIpB5sx68fDCOmOGSUbdgOCV+S+O
|
18
|
+
CyTFctYlJNXZgv2kl76TII7jbZikT/7hVOhCO48OdMQ/s26zabbJrcV2pJOLKKkP
|
19
|
+
BKX4xDo6SbsGmqjFkknT6WiiE94rQxGCb9JNiSyl3SncEw+Ysx6yVKYB5WAEy8s1
|
20
|
+
M0VQvDzd77bxj3lx/P6ifll3yUs=
|
20
21
|
-----END CERTIFICATE-----
|
@@ -4,7 +4,7 @@ module MetaTags
|
|
4
4
|
module Generators
|
5
5
|
class InstallGenerator < Rails::Generators::Base
|
6
6
|
desc "Copy MetaTags default files"
|
7
|
-
source_root File.expand_path(
|
7
|
+
source_root File.expand_path("templates", __dir__)
|
8
8
|
|
9
9
|
def copy_config
|
10
10
|
template "config/initializers/meta_tags.rb"
|
@@ -9,6 +9,15 @@ MetaTags.configure do |config|
|
|
9
9
|
# When true, site title will be truncated instead of title. Default is false.
|
10
10
|
# config.truncate_site_title_first = false
|
11
11
|
|
12
|
+
# Add HTML attributes to the <title> HTML tag. Default is {}.
|
13
|
+
# config.title_tag_attributes = {}
|
14
|
+
|
15
|
+
# Natural separator when truncating. Default is " " (space character).
|
16
|
+
# Set to nil to disable natural separator.
|
17
|
+
# This also allows you to use a whitespace regular expression (/\s/) or
|
18
|
+
# a Unicode space (/\p{Space}/).
|
19
|
+
# config.truncate_on_natural_separator = " "
|
20
|
+
|
12
21
|
# Maximum length of the page description. Default is 300.
|
13
22
|
# Set to nil or 0 to remove limits.
|
14
23
|
# config.description_limit = 300
|
data/lib/meta-tags.rb
CHANGED
@@ -6,9 +6,15 @@ module MetaTags
|
|
6
6
|
# How many characters to truncate title to.
|
7
7
|
attr_accessor :title_limit
|
8
8
|
|
9
|
+
# HTML attributes for the title tag.
|
10
|
+
attr_accessor :title_tag_attributes
|
11
|
+
|
9
12
|
# Truncate site_title instead of title.
|
10
13
|
attr_accessor :truncate_site_title_first
|
11
14
|
|
15
|
+
# A string or regexp separator to truncate text at a natural break.
|
16
|
+
attr_accessor :truncate_on_natural_separator
|
17
|
+
|
12
18
|
# How many characters to truncate description to.
|
13
19
|
attr_accessor :description_limit
|
14
20
|
|
@@ -47,25 +53,25 @@ module MetaTags
|
|
47
53
|
def default_property_tags
|
48
54
|
[
|
49
55
|
# App Link metadata https://developers.facebook.com/docs/applinks/metadata-reference
|
50
|
-
|
56
|
+
"al",
|
51
57
|
# Open Graph Markup https://developers.facebook.com/docs/sharing/webmasters#markup
|
52
|
-
|
53
|
-
|
58
|
+
"fb",
|
59
|
+
"og",
|
54
60
|
# Facebook OpenGraph Object Types https://developers.facebook.com/docs/reference/opengraph
|
55
61
|
# Note that these tags are used in a regex, so including e.g. 'restaurant' will affect
|
56
62
|
# 'restaurant:category', 'restaurant:price_rating', and anything else under that namespace.
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
63
|
+
"article",
|
64
|
+
"book",
|
65
|
+
"books",
|
66
|
+
"business",
|
67
|
+
"fitness",
|
68
|
+
"game",
|
69
|
+
"music",
|
70
|
+
"place",
|
71
|
+
"product",
|
72
|
+
"profile",
|
73
|
+
"restaurant",
|
74
|
+
"video"
|
69
75
|
].freeze
|
70
76
|
end
|
71
77
|
|
@@ -76,9 +82,11 @@ module MetaTags
|
|
76
82
|
def reset_defaults!
|
77
83
|
@title_limit = 70
|
78
84
|
@truncate_site_title_first = false
|
85
|
+
@truncate_on_natural_separator = " "
|
86
|
+
@title_tag_attributes = {}
|
79
87
|
@description_limit = 300
|
80
88
|
@keywords_limit = 255
|
81
|
-
@keywords_separator =
|
89
|
+
@keywords_separator = ", "
|
82
90
|
@keywords_lowercase = true
|
83
91
|
@property_tags = default_property_tags.dup
|
84
92
|
@open_meta_tags = true
|
@@ -15,8 +15,8 @@ module MetaTags
|
|
15
15
|
# Processes the <tt>@page_title</tt>, <tt>@page_keywords</tt>, and
|
16
16
|
# <tt>@page_description</tt> instance variables and calls +render+.
|
17
17
|
def render(*args, &block)
|
18
|
-
meta_tags[:title]
|
19
|
-
meta_tags[:keywords]
|
18
|
+
meta_tags[:title] = @page_title if defined?(@page_title) && @page_title
|
19
|
+
meta_tags[:keywords] = @page_keywords if defined?(@page_keywords) && @page_keywords
|
20
20
|
meta_tags[:description] = @page_description if defined?(@page_description) && @page_description
|
21
21
|
|
22
22
|
super
|
@@ -25,7 +25,7 @@ module MetaTags
|
|
25
25
|
# Set meta tags for the page.
|
26
26
|
#
|
27
27
|
# See <tt>MetaTags::ViewHelper#set_meta_tags</tt> for details.
|
28
|
-
def set_meta_tags(meta_tags)
|
28
|
+
def set_meta_tags(meta_tags)
|
29
29
|
self.meta_tags.update(meta_tags)
|
30
30
|
end
|
31
31
|
protected :set_meta_tags
|
@@ -39,12 +39,12 @@ module MetaTags
|
|
39
39
|
#
|
40
40
|
def update(object = {})
|
41
41
|
meta_tags = if object.respond_to?(:to_meta_tags)
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
42
|
+
# @type var object: _MetaTagish & Object
|
43
|
+
object.to_meta_tags
|
44
|
+
else
|
45
|
+
# @type var object: Hash[String | Symbol, untyped]
|
46
|
+
object
|
47
|
+
end
|
48
48
|
@meta_tags.deep_merge! normalize_open_graph(meta_tags)
|
49
49
|
end
|
50
50
|
|
@@ -79,7 +79,7 @@ module MetaTags
|
|
79
79
|
old_site = @meta_tags[:site]
|
80
80
|
@meta_tags[:site] = nil
|
81
81
|
full_title = with_defaults(defaults) { extract_full_title }
|
82
|
-
full_title.presence || old_site ||
|
82
|
+
full_title.presence || old_site || ""
|
83
83
|
ensure
|
84
84
|
@meta_tags[:site] = old_site
|
85
85
|
end
|
@@ -106,10 +106,10 @@ module MetaTags
|
|
106
106
|
# @return [String] page title.
|
107
107
|
#
|
108
108
|
def extract_full_title
|
109
|
-
site_title = extract(:site) ||
|
110
|
-
title
|
111
|
-
separator
|
112
|
-
reverse
|
109
|
+
site_title = extract(:site) || ""
|
110
|
+
title = extract_title
|
111
|
+
separator = extract_separator
|
112
|
+
reverse = extract(:reverse) == true
|
113
113
|
|
114
114
|
TextNormalizer.normalize_title(site_title, title, separator, reverse)
|
115
115
|
end
|
@@ -136,15 +136,15 @@ module MetaTags
|
|
136
136
|
def extract_separator
|
137
137
|
if meta_tags[:separator] == false
|
138
138
|
# Special case: if separator is hidden, do not display suffix/prefix
|
139
|
-
prefix = separator = suffix =
|
139
|
+
prefix = separator = suffix = ""
|
140
140
|
else
|
141
|
-
prefix
|
142
|
-
separator = extract_separator_section(:separator,
|
143
|
-
suffix
|
141
|
+
prefix = extract_separator_section(:prefix, " ")
|
142
|
+
separator = extract_separator_section(:separator, "|")
|
143
|
+
suffix = extract_separator_section(:suffix, " ")
|
144
144
|
end
|
145
145
|
delete(:separator, :prefix, :suffix)
|
146
146
|
|
147
|
-
TextNormalizer.safe_join([prefix, separator, suffix],
|
147
|
+
TextNormalizer.safe_join([prefix, separator, suffix], "")
|
148
148
|
end
|
149
149
|
|
150
150
|
# Extracts noindex settings as a Hash mapping noindex tag name to value.
|
@@ -159,12 +159,12 @@ module MetaTags
|
|
159
159
|
[:noindex, :index],
|
160
160
|
# follow has higher priority than nofollow
|
161
161
|
[:follow, :nofollow],
|
162
|
-
:noarchive
|
162
|
+
:noarchive
|
163
163
|
].each do |attributes|
|
164
164
|
calculate_robots_attributes(result, attributes)
|
165
165
|
end
|
166
166
|
|
167
|
-
result.transform_values { |v| v.join(
|
167
|
+
result.transform_values { |v| v.join(", ") }
|
168
168
|
end
|
169
169
|
|
170
170
|
protected
|
@@ -188,7 +188,7 @@ module MetaTags
|
|
188
188
|
# @return [String] separator segment value.
|
189
189
|
#
|
190
190
|
def extract_separator_section(name, default)
|
191
|
-
meta_tags[name] == false ?
|
191
|
+
(meta_tags[name] == false) ? "" : (meta_tags[name] || default)
|
192
192
|
end
|
193
193
|
|
194
194
|
# Extracts robots attribute (noindex, nofollow, etc) name and value.
|
@@ -197,11 +197,11 @@ module MetaTags
|
|
197
197
|
# @return [Array<String>] pair of noindex attribute name and value.
|
198
198
|
#
|
199
199
|
def extract_robots_attribute(name)
|
200
|
-
noindex
|
201
|
-
noindex_name
|
200
|
+
noindex = extract(name)
|
201
|
+
noindex_name = (noindex.is_a?(String) || noindex.is_a?(Array)) ? noindex : "robots"
|
202
202
|
noindex_value = noindex ? name.to_s : nil
|
203
203
|
|
204
|
-
[
|
204
|
+
[noindex_name, noindex_value]
|
205
205
|
end
|
206
206
|
|
207
207
|
def calculate_robots_attributes(result, attributes)
|
data/lib/meta_tags/railtie.rb
CHANGED
@@ -2,15 +2,15 @@
|
|
2
2
|
|
3
3
|
module MetaTags
|
4
4
|
class Railtie < Rails::Railtie
|
5
|
-
initializer
|
5
|
+
initializer "meta_tags.setup_action_controller" do
|
6
6
|
ActiveSupport.on_load :action_controller do
|
7
|
-
|
7
|
+
include MetaTags::ControllerHelper
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
11
|
-
initializer
|
11
|
+
initializer "meta_tags.setup_action_view" do
|
12
12
|
ActiveSupport.on_load :action_view do
|
13
|
-
|
13
|
+
include MetaTags::ViewHelper
|
14
14
|
end
|
15
15
|
end
|
16
16
|
end
|
data/lib/meta_tags/renderer.rb
CHANGED
@@ -59,7 +59,11 @@ module MetaTags
|
|
59
59
|
normalized_meta_tags[:site] = meta_tags[:site]
|
60
60
|
title = meta_tags.extract_full_title
|
61
61
|
normalized_meta_tags[:full_title] = title
|
62
|
-
|
62
|
+
default_attributes = MetaTags.config.title_tag_attributes || {}
|
63
|
+
|
64
|
+
if title.present?
|
65
|
+
tags << ContentTag.new(:title, {content: title}.with_defaults(default_attributes))
|
66
|
+
end
|
63
67
|
end
|
64
68
|
|
65
69
|
# Renders icon(s) tag.
|
@@ -71,12 +75,12 @@ module MetaTags
|
|
71
75
|
return unless icon
|
72
76
|
|
73
77
|
# String? Value is an href
|
74
|
-
icon = [{
|
78
|
+
icon = [{href: icon}] if icon.is_a?(String)
|
75
79
|
# Hash? Single icon instead of a list of icons
|
76
|
-
icon = [icon] if icon.
|
80
|
+
icon = [icon] if icon.is_a?(Hash)
|
77
81
|
|
78
82
|
icon.each do |icon_params|
|
79
|
-
icon_params = {
|
83
|
+
icon_params = {rel: "icon", type: "image/x-icon"}.with_indifferent_access.merge(icon_params)
|
80
84
|
tags << Tag.new(:link, icon_params)
|
81
85
|
end
|
82
86
|
end
|
@@ -88,7 +92,7 @@ module MetaTags
|
|
88
92
|
# @see TextNormalizer
|
89
93
|
#
|
90
94
|
def render_with_normalization(tags, name)
|
91
|
-
value = TextNormalizer.public_send("normalize_#{name}", meta_tags.extract(name))
|
95
|
+
value = TextNormalizer.public_send(:"normalize_#{name}", meta_tags.extract(name))
|
92
96
|
normalized_meta_tags[name] = value
|
93
97
|
tags << Tag.new(:meta, name: name, content: value) if value.present?
|
94
98
|
end
|
@@ -109,7 +113,7 @@ module MetaTags
|
|
109
113
|
#
|
110
114
|
def render_refresh(tags)
|
111
115
|
refresh = meta_tags.extract(:refresh)
|
112
|
-
tags << Tag.new(:meta,
|
116
|
+
tags << Tag.new(:meta, "http-equiv" => "refresh", :content => refresh.to_s) if refresh.present?
|
113
117
|
end
|
114
118
|
|
115
119
|
# Renders alternate link tags.
|
@@ -120,13 +124,13 @@ module MetaTags
|
|
120
124
|
alternate = meta_tags.extract(:alternate)
|
121
125
|
return unless alternate
|
122
126
|
|
123
|
-
if alternate.
|
127
|
+
if alternate.is_a?(Hash)
|
124
128
|
alternate.each do |hreflang, href|
|
125
|
-
tags << Tag.new(:link, rel:
|
129
|
+
tags << Tag.new(:link, rel: "alternate", href: href, hreflang: hreflang) if href.present?
|
126
130
|
end
|
127
|
-
elsif alternate.
|
131
|
+
elsif alternate.is_a?(Array)
|
128
132
|
alternate.each do |link_params|
|
129
|
-
tags << Tag.new(:link, {
|
133
|
+
tags << Tag.new(:link, {rel: "alternate"}.with_indifferent_access.merge(link_params))
|
130
134
|
end
|
131
135
|
end
|
132
136
|
end
|
@@ -143,7 +147,7 @@ module MetaTags
|
|
143
147
|
title = open_search[:title]
|
144
148
|
|
145
149
|
type = "application/opensearchdescription+xml"
|
146
|
-
tags << Tag.new(:link, rel:
|
150
|
+
tags << Tag.new(:link, rel: "search", type: type, href: href, title: title) if href.present?
|
147
151
|
end
|
148
152
|
|
149
153
|
# Renders links.
|
@@ -151,7 +155,7 @@ module MetaTags
|
|
151
155
|
# @param [Array<Tag>] tags a buffer object to store tag in.
|
152
156
|
#
|
153
157
|
def render_links(tags)
|
154
|
-
[
|
158
|
+
[:amphtml, :prev, :next, :image_src, :manifest].each do |tag_name|
|
155
159
|
href = meta_tags.extract(tag_name)
|
156
160
|
if href.present?
|
157
161
|
@normalized_meta_tags[tag_name] = href
|
@@ -189,7 +193,7 @@ module MetaTags
|
|
189
193
|
#
|
190
194
|
def render_hash(tags, key, **opts)
|
191
195
|
data = meta_tags.meta_tags[key]
|
192
|
-
return unless data.
|
196
|
+
return unless data.is_a?(Hash)
|
193
197
|
|
194
198
|
process_hash(tags, key, data, **opts)
|
195
199
|
meta_tags.extract(key)
|
@@ -202,7 +206,7 @@ module MetaTags
|
|
202
206
|
def render_custom(tags)
|
203
207
|
meta_tags.meta_tags.each do |name, data|
|
204
208
|
Array(data).each do |val|
|
205
|
-
tags << Tag.new(:meta, configured_name_key(name) => name, content
|
209
|
+
tags << Tag.new(:meta, configured_name_key(name) => name, :content => val)
|
206
210
|
end
|
207
211
|
meta_tags.extract(name)
|
208
212
|
end
|
@@ -217,14 +221,14 @@ module MetaTags
|
|
217
221
|
#
|
218
222
|
def process_tree(tags, property, content, itemprop: nil, **opts)
|
219
223
|
method = case content
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
224
|
+
when Hash
|
225
|
+
:process_hash
|
226
|
+
when Array
|
227
|
+
:process_array
|
228
|
+
else
|
229
|
+
iprop = itemprop
|
230
|
+
:render_tag
|
231
|
+
end
|
228
232
|
__send__(method, tags, property, content, itemprop: iprop, **opts)
|
229
233
|
end
|
230
234
|
|
@@ -237,18 +241,18 @@ module MetaTags
|
|
237
241
|
def process_hash(tags, property, content, **opts)
|
238
242
|
itemprop = content.delete(:itemprop)
|
239
243
|
content.each do |key, value|
|
240
|
-
if key.to_s ==
|
244
|
+
if key.to_s == "_"
|
241
245
|
iprop = itemprop
|
242
246
|
key = property
|
243
247
|
else
|
244
248
|
key = "#{property}:#{key}"
|
245
249
|
end
|
246
250
|
|
247
|
-
normalized_value = if value.
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
251
|
+
normalized_value = if value.is_a?(Symbol)
|
252
|
+
normalized_meta_tags[value]
|
253
|
+
else
|
254
|
+
value
|
255
|
+
end
|
252
256
|
process_tree(tags, key, normalized_value, **opts.merge(itemprop: iprop))
|
253
257
|
end
|
254
258
|
end
|
@@ -273,7 +277,7 @@ module MetaTags
|
|
273
277
|
#
|
274
278
|
def render_tag(tags, name, value, itemprop: nil)
|
275
279
|
name_key ||= configured_name_key(name)
|
276
|
-
tags << Tag.new(:meta, name_key => name.to_s, content
|
280
|
+
tags << Tag.new(:meta, name_key => name.to_s, :content => value, :itemprop => itemprop) if value.present?
|
277
281
|
end
|
278
282
|
|
279
283
|
# Returns meta tag property name for a give meta tag based on the
|
@@ -44,7 +44,7 @@ module MetaTags
|
|
44
44
|
# serves the same purpose we could just as it to convert itself to str
|
45
45
|
# and continue from there
|
46
46
|
description = cleanup_string(description)
|
47
|
-
return
|
47
|
+
return "" if description.blank?
|
48
48
|
|
49
49
|
truncate(description, MetaTags.config.description_limit)
|
50
50
|
end
|
@@ -56,7 +56,7 @@ module MetaTags
|
|
56
56
|
#
|
57
57
|
def normalize_keywords(keywords)
|
58
58
|
keywords = cleanup_strings(keywords)
|
59
|
-
return
|
59
|
+
return "" if keywords.blank?
|
60
60
|
|
61
61
|
keywords.each(&:downcase!) if MetaTags.config.keywords_lowercase
|
62
62
|
separator = cleanup_string MetaTags.config.keywords_separator, strip: false
|
@@ -107,12 +107,12 @@ module MetaTags
|
|
107
107
|
# space characters squashed into a single space.
|
108
108
|
#
|
109
109
|
def cleanup_string(string, strip: true)
|
110
|
-
return
|
111
|
-
raise ArgumentError,
|
110
|
+
return "" if string.nil?
|
111
|
+
raise ArgumentError, "Expected a string or an object that implements #to_str" unless string.respond_to?(:to_str)
|
112
112
|
|
113
113
|
s = strip_tags(string.to_str)
|
114
114
|
s = s.dup if s.frozen?
|
115
|
-
s.gsub!(/\s+/,
|
115
|
+
s.gsub!(/\s+/, " ")
|
116
116
|
s.strip! if strip
|
117
117
|
|
118
118
|
s
|
@@ -134,18 +134,17 @@ module MetaTags
|
|
134
134
|
#
|
135
135
|
# @param [String] string input strings.
|
136
136
|
# @param [Integer,nil] limit characters number to truncate to.
|
137
|
-
# @param [String] natural_separator natural separator to truncate at.
|
138
137
|
# @return [String] truncated string.
|
139
138
|
#
|
140
|
-
def truncate(string, limit = nil
|
141
|
-
return string if limit.to_i == 0
|
139
|
+
def truncate(string, limit = nil)
|
140
|
+
return string if limit.to_i == 0
|
142
141
|
|
143
142
|
helpers.truncate(
|
144
143
|
string,
|
145
|
-
length:
|
146
|
-
separator:
|
147
|
-
omission:
|
148
|
-
escape:
|
144
|
+
length: limit,
|
145
|
+
separator: MetaTags.config.truncate_on_natural_separator,
|
146
|
+
omission: "",
|
147
|
+
escape: true
|
149
148
|
)
|
150
149
|
end
|
151
150
|
|
@@ -154,10 +153,9 @@ module MetaTags
|
|
154
153
|
# @param [Array<String>] string_array input strings.
|
155
154
|
# @param [Integer,nil] limit characters number to truncate to.
|
156
155
|
# @param [String] separator separator that will be used to join array later.
|
157
|
-
# @param [String] natural_separator natural separator to truncate at.
|
158
156
|
# @return [Array<String>] truncated array of strings.
|
159
157
|
#
|
160
|
-
def truncate_array(string_array, limit = nil, separator =
|
158
|
+
def truncate_array(string_array, limit = nil, separator = "")
|
161
159
|
return string_array if limit.nil? || limit <= 0
|
162
160
|
|
163
161
|
length = 0
|
@@ -167,7 +165,7 @@ module MetaTags
|
|
167
165
|
limit_left = calculate_limit_left(limit, length, result, separator)
|
168
166
|
|
169
167
|
if string.length > limit_left
|
170
|
-
result << truncate(string, limit_left
|
168
|
+
result << truncate(string, limit_left)
|
171
169
|
break string_array
|
172
170
|
end
|
173
171
|
|
@@ -188,14 +186,14 @@ module MetaTags
|
|
188
186
|
end
|
189
187
|
|
190
188
|
def truncate_title(site_title, title, separator)
|
191
|
-
global_limit = MetaTags.config.title_limit.to_i
|
189
|
+
global_limit = MetaTags.config.title_limit.to_i
|
192
190
|
if global_limit > 0
|
193
191
|
site_title_limited_length, title_limited_length = calculate_title_limits(
|
194
|
-
site_title, title, separator, global_limit
|
192
|
+
site_title, title, separator, global_limit
|
195
193
|
)
|
196
194
|
|
197
|
-
title = title_limited_length > 0 ? truncate_array(title, title_limited_length, separator) : []
|
198
|
-
site_title = site_title_limited_length > 0 ? truncate(site_title, site_title_limited_length) : nil
|
195
|
+
title = (title_limited_length > 0) ? truncate_array(title, title_limited_length, separator) : []
|
196
|
+
site_title = (site_title_limited_length > 0) ? truncate(site_title, site_title_limited_length) : nil
|
199
197
|
end
|
200
198
|
|
201
199
|
[site_title, title]
|
@@ -208,13 +206,13 @@ module MetaTags
|
|
208
206
|
main_length = main_title.map(&:length).sum + ((main_title.size - 1) * separator.length)
|
209
207
|
main_limited_length = global_limit
|
210
208
|
|
211
|
-
secondary_limited_length = global_limit - (main_length > 0 ? main_length + separator.length : 0)
|
209
|
+
secondary_limited_length = global_limit - ((main_length > 0) ? main_length + separator.length : 0)
|
212
210
|
secondary_limited_length = [0, secondary_limited_length].max
|
213
211
|
|
214
212
|
if MetaTags.config.truncate_site_title_first
|
215
|
-
[
|
213
|
+
[secondary_limited_length, main_limited_length]
|
216
214
|
else
|
217
|
-
[
|
215
|
+
[main_limited_length, secondary_limited_length]
|
218
216
|
end
|
219
217
|
end
|
220
218
|
end
|
data/lib/meta_tags/version.rb
CHANGED
@@ -55,7 +55,7 @@ module MetaTags
|
|
55
55
|
#
|
56
56
|
# @see #display_meta_tags
|
57
57
|
#
|
58
|
-
def title(title = nil, headline =
|
58
|
+
def title(title = nil, headline = "")
|
59
59
|
set_meta_tags(title: title) unless title.nil?
|
60
60
|
headline.presence || meta_tags[:title]
|
61
61
|
end
|
@@ -203,7 +203,7 @@ module MetaTags
|
|
203
203
|
# <div data-page-container="true" title="<%= display_title title: 'My Page', site: 'PJAX Site' %>">
|
204
204
|
#
|
205
205
|
def display_title(defaults = {})
|
206
|
-
|
206
|
+
meta_tags.full_title(defaults)
|
207
207
|
end
|
208
208
|
end
|
209
209
|
end
|
data/lib/meta_tags.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require "set"
|
4
|
+
require "active_support/core_ext/hash/indifferent_access"
|
5
5
|
|
6
6
|
# MetaTags gem namespace.
|
7
7
|
module MetaTags
|
@@ -24,15 +24,15 @@ module MetaTags
|
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
|
-
require
|
27
|
+
require "meta_tags/version"
|
28
28
|
|
29
|
-
require
|
30
|
-
require
|
31
|
-
require
|
32
|
-
require
|
33
|
-
require
|
34
|
-
require
|
35
|
-
require
|
36
|
-
require
|
29
|
+
require "meta_tags/configuration"
|
30
|
+
require "meta_tags/controller_helper"
|
31
|
+
require "meta_tags/meta_tags_collection"
|
32
|
+
require "meta_tags/renderer"
|
33
|
+
require "meta_tags/tag"
|
34
|
+
require "meta_tags/content_tag"
|
35
|
+
require "meta_tags/text_normalizer"
|
36
|
+
require "meta_tags/view_helper"
|
37
37
|
|
38
|
-
require
|
38
|
+
require "meta_tags/railtie" if defined?(Rails)
|
data/sig/lib/_internal/rails.rbs
CHANGED
@@ -1,9 +1,12 @@
|
|
1
1
|
class ::Hash[unchecked out K, unchecked out V]
|
2
2
|
def with_indifferent_access: () -> ActiveSupport::HashWithIndifferentAccess[K, V]
|
3
3
|
def deep_merge!: (instance | ActiveSupport::HashWithIndifferentAccess[K, V] other) -> self
|
4
|
+
def with_defaults: (instance | ActiveSupport::HashWithIndifferentAccess[K, V] other) -> self
|
4
5
|
end
|
5
6
|
|
6
7
|
class ::Object
|
8
|
+
$OFS: String
|
9
|
+
|
7
10
|
def presence: () -> self?
|
8
11
|
def blank?: () -> bool
|
9
12
|
def present?: () -> bool
|
@@ -1,7 +1,14 @@
|
|
1
1
|
module MetaTags
|
2
2
|
class Configuration
|
3
|
+
type html_tag_key = String | Symbol
|
4
|
+
type html_tag_value = Hash[html_tag_key, html_tag_value] | html_tag_content
|
5
|
+
type html_tag_content = String? | Symbol | (_Stringish & Object)
|
6
|
+
|
7
|
+
|
3
8
|
attr_accessor title_limit: Integer?
|
4
9
|
attr_accessor truncate_site_title_first: bool
|
10
|
+
attr_accessor truncate_on_natural_separator: String?|Regexp
|
11
|
+
attr_accessor title_tag_attributes: Hash[html_tag_key, html_tag_value]?
|
5
12
|
attr_accessor description_limit: Integer
|
6
13
|
attr_accessor keywords_limit: Integer
|
7
14
|
attr_accessor keywords_separator: String
|