seo_cache 1.0.2 → 1.0.6

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: dde4a37e1374c8be6416313e684356041177425e0cf5c2466d4fc7c60818626d
4
- data.tar.gz: 9e5879c7af42860ff332e06eb36343cd650bf8a89c634b386a8073059d9c4aa2
3
+ metadata.gz: 470c0f8bf9bee91e738987dd31618d612d4f8007fe5d486bce1c4d7c0f1053de
4
+ data.tar.gz: cc0bb416f7893fb08a97e845635c374bf8dbc846127724077729d6870ceb93ec
5
5
  SHA512:
6
- metadata.gz: a391af74f2c3d9848cce8bb4b1daa228c3296e019bed8ab1126dda1b9a52825351a885bfd9c2067671f8ff645a4bb7b88d36d1fb8298790e04c48e36ab93daf5
7
- data.tar.gz: 8aa95c5b23d5120b1a5848d115ed3ceb75ec2019abaf507a7bcf076fa9d391ffe750f1750bbcc4b484d497303544f68ab33788a11bd88a6d1bc5c10aae95f682
6
+ metadata.gz: 6057c2afeb50daf1a93c1df0e9f6c90d55be66688445a417dca2d6b434d0dfc587e487be4d4404d3897c783f0e3d3d2880d5f9b6524b35975e5c87031028e4c2
7
+ data.tar.gz: 5822d662fdbbf6d2c47bb21ed627697c52760e6133eff49978f11c3ad6fd984cb0b67c8b6e778e6bc43742a2ba2241bdf81d24f810333e92be60c840d159559c
data/.rubocop.yml CHANGED
@@ -1,18 +1,20 @@
1
1
  # Documentation
2
2
  # https://github.com/bbatsov/rubocop/blob/master/config/default.yml
3
- # http://rubocop.readthedocs.io/en/latest
3
+ # http://rubocop.readthedocs.io/en/latest
4
+
5
+ require:
6
+ - rubocop-rails
7
+ - rubocop-rspec
8
+ - rubocop-performance
4
9
 
5
10
  AllCops:
6
- TargetRubyVersion: 2.6
11
+ TargetRubyVersion: 3.0
7
12
 
8
13
  Bundler/OrderedGems:
9
14
  Enabled: false
10
15
 
11
- Layout/HashAlignment:
12
- Enabled: false
13
-
14
- Layout/ParameterAlignment:
15
- Enabled: false
16
+ Gemspec/DateAssignment:
17
+ Enabled: true
16
18
 
17
19
  Layout/CaseIndentation:
18
20
  Enabled: false
@@ -42,9 +44,15 @@ Layout/FirstArrayElementIndentation:
42
44
  Layout/FirstHashElementIndentation:
43
45
  Enabled: false
44
46
 
47
+ Layout/HashAlignment:
48
+ Enabled: false
49
+
45
50
  Layout/LeadingCommentSpace:
46
51
  Enabled: false
47
52
 
53
+ Layout/LineLength:
54
+ Enabled: false
55
+
48
56
  Layout/MultilineBlockLayout:
49
57
  Enabled: false
50
58
 
@@ -57,20 +65,73 @@ Layout/MultilineMethodCallIndentation:
57
65
  Layout/MultilineOperationIndentation:
58
66
  Enabled: false
59
67
 
68
+ Layout/ParameterAlignment:
69
+ Enabled: false
70
+
60
71
  Layout/SpaceAroundOperators:
61
72
  Enabled: false
62
73
 
74
+ Layout/SpaceBeforeBrackets:
75
+ Enabled: true
76
+
63
77
  Layout/SpaceInLambdaLiteral:
64
78
  Enabled: false
65
79
 
66
80
  Layout/TrailingWhitespace:
67
81
  Enabled: false
68
82
 
83
+ Lint/AmbiguousAssignment:
84
+ Enabled: true
85
+
69
86
  Lint/AmbiguousBlockAssociation:
70
87
  Enabled: false
71
88
 
89
+ Lint/DeprecatedConstants:
90
+ Enabled: true
91
+
92
+ Lint/DuplicateBranch:
93
+ Enabled: true
94
+
95
+ Lint/DuplicateRegexpCharacterClassElement:
96
+ Enabled: true
97
+
98
+ Lint/EmptyBlock:
99
+ Enabled: true
100
+
101
+ Lint/EmptyClass:
102
+ Enabled: true
103
+
104
+ Lint/LambdaWithoutLiteralBlock:
105
+ Enabled: true
106
+
107
+ Lint/NoReturnInBeginEndBlocks:
108
+ Enabled: true
109
+
110
+ Lint/NumberedParameterAssignment:
111
+ Enabled: true
112
+
113
+ Lint/OrAssignmentToConstant:
114
+ Enabled: true
115
+
116
+ Lint/RedundantDirGlobSort:
117
+ Enabled: true
118
+
119
+ Lint/SymbolConversion:
120
+ Enabled: true
121
+
122
+ Lint/ToEnumArguments:
123
+ Enabled: true
124
+
125
+ Lint/TripleQuotes:
126
+ Enabled: true
127
+
128
+ Lint/UnexpectedBlockArity:
129
+ Enabled: true
130
+
131
+ Lint/UnmodifiedReduceAccumulator:
132
+ Enabled: true
133
+
72
134
  Metrics/AbcSize:
73
- # The ABC size is a calculated magnitude, so this number can be a Fixnum or a Float.
74
135
  Max: 240
75
136
 
76
137
  Metrics/BlockLength:
@@ -80,14 +141,14 @@ Metrics/BlockNesting:
80
141
  Max: 4
81
142
 
82
143
  Metrics/ClassLength:
83
- CountComments: false # count full line comments?
144
+ CountComments: false
84
145
  Max: 600
85
146
 
86
147
  Metrics/CyclomaticComplexity:
87
148
  Enabled: false
88
149
 
89
150
  Metrics/MethodLength:
90
- CountComments: false # count full line comments?
151
+ CountComments: false
91
152
  Max: 120
92
153
 
93
154
  Metrics/PerceivedComplexity:
@@ -96,6 +157,168 @@ Metrics/PerceivedComplexity:
96
157
  Naming/RescuedExceptionsVariableName:
97
158
  Enabled: false
98
159
 
160
+ Performance/AncestorsInclude:
161
+ Enabled: true
162
+
163
+ Performance/BigDecimalWithNumericArgument:
164
+ Enabled: true
165
+
166
+ Performance/BlockGivenWithExplicitBlock:
167
+ Enabled: true
168
+
169
+ Performance/CollectionLiteralInLoop:
170
+ Enabled: true
171
+
172
+ Performance/ConstantRegexp:
173
+ Enabled: true
174
+
175
+ Performance/MapCompact:
176
+ Enabled: true
177
+
178
+ Performance/MethodObjectAsBlock:
179
+ Enabled: true
180
+
181
+ Performance/RedundantEqualityComparisonBlock:
182
+ Enabled: true
183
+
184
+ Performance/RedundantSortBlock:
185
+ Enabled: true
186
+
187
+ Performance/RedundantSplitRegexpArgument:
188
+ Enabled: true
189
+
190
+ Performance/RedundantStringChars:
191
+ Enabled: true
192
+
193
+ Performance/ReverseFirst:
194
+ Enabled: true
195
+
196
+ Performance/SortReverse:
197
+ Enabled: true
198
+
199
+ Performance/Squeeze:
200
+ Enabled: true
201
+
202
+ Performance/StringInclude:
203
+ Enabled: true
204
+
205
+ Performance/Sum:
206
+ Enabled: true
207
+
208
+ Rails/ActiveRecordCallbacksOrder:
209
+ Enabled: true
210
+
211
+ Rails/AfterCommitOverride:
212
+ Enabled: true
213
+
214
+ Rails/AttributeDefaultBlockValue:
215
+ Enabled: true
216
+
217
+ Rails/DynamicFindBy:
218
+ Enabled: false
219
+
220
+ Rails/FindBy:
221
+ Enabled: false
222
+
223
+ Rails/FindById:
224
+ Enabled: true
225
+
226
+ Rails/HasManyOrHasOneDependent:
227
+ Enabled: false
228
+
229
+ Rails/Inquiry:
230
+ Enabled: true
231
+
232
+ Rails/InverseOf:
233
+ Enabled: false
234
+
235
+ Rails/MailerName:
236
+ Enabled: true
237
+
238
+ Rails/MatchRoute:
239
+ Enabled: true
240
+
241
+ Rails/NegateInclude:
242
+ Enabled: true
243
+
244
+ Rails/Pluck:
245
+ Enabled: true
246
+
247
+ Rails/OutputSafety:
248
+ Enabled: false
249
+
250
+ Rails/PluckInWhere:
251
+ Enabled: true
252
+
253
+ Rails/RenderInline:
254
+ Enabled: true
255
+
256
+ Rails/RenderPlainText:
257
+ Enabled: true
258
+
259
+ Rails/ShortI18n:
260
+ Enabled: true
261
+
262
+ Rails/SkipsModelValidations:
263
+ Enabled: false
264
+
265
+ Rails/SquishedSQLHeredocs:
266
+ Enabled: true
267
+
268
+ Rails/UnknownEnv:
269
+ Enabled: false
270
+
271
+ Rails/Validation:
272
+ Enabled: false
273
+
274
+ Rails/WhereEquals:
275
+ Enabled: true
276
+
277
+ Rails/WhereExists:
278
+ Enabled: true
279
+
280
+ Rails/WhereNot:
281
+ Enabled: true
282
+
283
+ RSpec/BeforeAfterAll:
284
+ Enabled: false
285
+
286
+ RSpec/ContextWording:
287
+ Enabled: false
288
+
289
+ RSpec/DescribedClass:
290
+ Enabled: false
291
+
292
+ RSpec/ExampleLength:
293
+ Max: 20
294
+
295
+ RSpec/Capybara:
296
+ Enabled: false
297
+
298
+ RSpec/ImplicitExpect:
299
+ Enabled: false
300
+
301
+ RSpec/ImplicitSubject:
302
+ Enabled: false
303
+
304
+ RSpec/InstanceVariable:
305
+ Enabled: false
306
+
307
+ RSpec/LeadingSubject:
308
+ Enabled: false
309
+
310
+ RSpec/MultipleExpectations:
311
+ Max: 10
312
+
313
+ RSpec/MultipleMemoizedHelpers:
314
+ Max: 8
315
+
316
+ RSpec/NestedGroups:
317
+ Max: 4
318
+
319
+ Style/ArgumentsForwarding:
320
+ Enabled: true
321
+
99
322
  Style/AsciiComments:
100
323
  Enabled: false
101
324
 
@@ -105,24 +328,63 @@ Style/BlockDelimiters:
105
328
  Style/ClassAndModuleChildren:
106
329
  Enabled: false
107
330
 
331
+ Style/CollectionCompact:
332
+ Enabled: true
333
+
108
334
  Style/ColonMethodCall:
109
335
  Enabled: false
110
336
 
111
337
  Style/CommandLiteral:
112
338
  Enabled: false
113
339
 
340
+ Style/Documentation:
341
+ Enabled: false
342
+
343
+ Style/DocumentDynamicEvalDefinition:
344
+ Enabled: true
345
+
114
346
  Style/DoubleNegation:
115
347
  Enabled: false
116
348
 
349
+ Style/EndlessMethod:
350
+ Enabled: true
351
+
117
352
  Style/GlobalVars:
118
353
  Enabled: false
119
354
 
355
+ Style/HashConversion:
356
+ Enabled: true
357
+
358
+ Style/HashEachMethods:
359
+ Enabled: true
360
+
361
+ Style/HashExcept:
362
+ Enabled: true
363
+
364
+ Style/HashTransformKeys:
365
+ Enabled: true
366
+
367
+ Style/HashTransformValues:
368
+ Enabled: true
369
+
370
+ Style/IfUnlessModifier:
371
+ Enabled: false
372
+
373
+ Style/IfWithBooleanLiteralBranches:
374
+ Enabled: true
375
+
120
376
  Style/Lambda:
121
377
  Enabled: false
122
378
 
123
379
  Style/MultilineIfModifier:
124
380
  Enabled: false
125
381
 
382
+ Style/NegatedIfElseCondition:
383
+ Enabled: true
384
+
385
+ Style/NilLambda:
386
+ Enabled: true
387
+
126
388
  Style/NumericPredicate:
127
389
  Enabled: false
128
390
 
@@ -130,6 +392,9 @@ Style/RedundantReturn:
130
392
  Enabled: false
131
393
  AllowMultipleReturnValues: true
132
394
 
395
+ Style/RedundantArgument:
396
+ Enabled: true
397
+
133
398
  Style/RedundantSelf:
134
399
  Enabled: false
135
400
 
@@ -139,5 +404,11 @@ Style/RegexpLiteral:
139
404
  Style/RescueModifier:
140
405
  Enabled: false
141
406
 
407
+ Style/StringChars:
408
+ Enabled: true
409
+
410
+ Style/SwapValues:
411
+ Enabled: true
412
+
142
413
  Style/SymbolArray:
143
414
  Enabled: false
data/CHANGELOG.md CHANGED
@@ -1,3 +1,19 @@
1
+ ## 1.0.6
2
+
3
+ - Logs only missed cache for success response
4
+
5
+ ## 1.0.5
6
+
7
+ - Use correct path for index page with multiple domain names
8
+
9
+ ## 1.0.4
10
+
11
+ - Add option to populate seo cache for multi-domains
12
+
13
+ ## 1.0.3
14
+
15
+ - Ensure page rendered status is present after head element
16
+
1
17
  ## 1.0.2
2
18
 
3
19
  - Do not log missed cache for ignored statuses
data/README.md CHANGED
@@ -227,6 +227,8 @@ end
227
227
 
228
228
  You can add the `force_cache: true` option to `SeoCache::PopulateCache` for overwrite cached data.
229
229
 
230
+ If your website has several domains (.com, .fr, ...), you need to generate your urls for each locale (each key is the locale). And use the `with_locale_keys: true` option.
231
+
230
232
  If you want to execute only through a rake task, you can comment the line which include the middleware. keep all options configured and remove only the middleware. Thus all pages will be cached and SeoCache isn't called for pages not in cache.
231
233
  It's useful if you have a script which generates all website pages (based on sitemap for instance) and you run script every day.
232
234
 
@@ -275,6 +277,8 @@ location / {
275
277
  rewrite ^/(.*)/$ /$1 last;
276
278
 
277
279
  try_files /seo_cache/$uri/index$cache_extension /seo_cache/$uri$cache_extension /seo_cache/$uri $uri @rubyproxy;
280
+ # Or for multi-domains:
281
+ # try_files /seo_cache/fr/$uri/index$cache_extension /seo_cache/fr/$uri$cache_extension /seo_cache/fr/$uri $uri @rubyproxy;
278
282
  }
279
283
 
280
284
  location @rubyproxy {
@@ -36,9 +36,15 @@ module SeoCache
36
36
  else
37
37
  Thread.new do
38
38
  prerender_data = page_render(env)
39
- # Extract status from render page or return 404
40
- status = prerender_data&.scan(/<!--status:(\d+)-->/)&.last&.first || 404
41
- after_render(env, prerender_data, status || 200)
39
+ # Extract status from render page or return success (200)
40
+ status = prerender_data&.scan(/<!--status:(\d+)-->/)&.last&.first || 200
41
+
42
+ if SeoCache.log_missed_cache && status.to_s.start_with?('2')
43
+ env_request = Rack::Request.new(env)
44
+ SeoCache.log("missed cache : #{env_request.path} (User agent: #{env_request.user_agent})")
45
+ end
46
+
47
+ after_render(env, prerender_data, status)
42
48
  end
43
49
  end
44
50
  elsif prerender_params?(env)
@@ -48,7 +54,7 @@ module SeoCache
48
54
  status_code = "<!--status:#{status}-->"
49
55
  # Cannot add at the top of file, Chrome removes leading comments...
50
56
  begin
51
- body_code = response.body.sub('<head>', "<head>#{status_code}")
57
+ body_code = response.body.sub(/<head( ?)(.*?)>/i, "<head\\1\\2>#{status_code}")
52
58
  return [status, headers, [body_code]]
53
59
  rescue
54
60
  return [status, headers, [nil]]
@@ -94,7 +100,7 @@ module SeoCache
94
100
  return false if SeoCache.blacklist_params.present? && SeoCache.blacklist_params.any? { |param| query_params.has_key?(param) }
95
101
 
96
102
  # if it is a bot and is requesting a resource...don't prerender
97
- return false if @extensions_to_ignore.any? { |extension| request.fullpath.include? extension }
103
+ return false if @extensions_to_ignore.any? { |extension| request.fullpath.include?(extension) }
98
104
 
99
105
  # if it is a bot and not requesting a resource and is not whitelisted...don't prerender
100
106
  return false if SeoCache.whitelist_urls.present? && SeoCache.whitelist_urls.all? { |whitelisted| !Regexp.new(whitelisted).match(request.fullpath) }
@@ -17,12 +17,12 @@ module SeoCache
17
17
  @redis.get(cache_path(path, extension)) if SeoCache.memory_cache? && @redis
18
18
  end
19
19
 
20
- def cache(content, path, extension = nil, gzip = Zlib::BEST_COMPRESSION)
20
+ def cache(content, path, locale_domain = nil, extension = nil, gzip = Zlib::BEST_COMPRESSION)
21
21
  instrument :write_page, path do
22
22
  if SeoCache.memory_cache? && @redis
23
- write_to_memory(content, cache_path(path, extension))
23
+ write_to_memory(content, cache_path(path, extension, locale_domain))
24
24
  else
25
- write_to_disk(content, cache_path(path, extension), gzip)
25
+ write_to_disk(content, cache_path(path, extension, locale_domain), gzip)
26
26
  end
27
27
  end
28
28
  end
@@ -51,22 +51,22 @@ module SeoCache
51
51
  SeoCache.cache_extension
52
52
  end
53
53
 
54
- def cache_file(path, extension)
54
+ def cache_file(path, extension, locale_domain)
55
55
  name = if path.empty? || path =~ %r{\A/+\z}
56
56
  '/index'
57
57
  else
58
58
  URI::Parser.new.unescape(path.chomp('/'))
59
59
  end
60
60
 
61
- if File.extname(name).empty?
62
- name + (extension || default_extension)
63
- else
64
- name
65
- end
61
+ name = "#{locale_domain}/#{name}" if locale_domain
62
+
63
+ name += extension || default_extension if File.extname(name).empty?
64
+
65
+ name
66
66
  end
67
67
 
68
- def cache_path(path, extension = nil)
69
- File.join(cache_directory, cache_file(path, extension))
68
+ def cache_path(path, extension = nil, locale_domain = nil)
69
+ File.join(cache_directory, cache_file(path, extension, locale_domain))
70
70
  end
71
71
 
72
72
  def write_to_memory(content, path)
@@ -11,27 +11,40 @@ module SeoCache
11
11
  @page_render = PageRender.new
12
12
  @page_caching = PageCaching.new
13
13
 
14
- @force_cache = options.fetch(:force_cache, false)
14
+ @force_cache = options.fetch(:force_cache, false)
15
+ @with_locale_keys = options.fetch(:with_locale_keys, false)
15
16
  end
16
17
 
17
18
  def perform
18
- @paths.each do |path|
19
- next if @page_caching.cache_exists?(path) && !@force_cache
20
-
21
- url = @host + path
22
- url += if path.include?('?')
23
- '&'
24
- else
25
- '?'
26
- end
27
- url += "#{SeoCache.prerender_url_param}=true"
28
-
29
- page_source = @page_render.get(url, false)
30
- @page_caching.cache(page_source, path) if page_source
19
+ if @with_locale_keys
20
+ @paths.each do |locale, paths|
21
+ paths.each do |path|
22
+ generate_cache(path, locale)
23
+ end
24
+ end
25
+ else
26
+ @paths.each do |path|
27
+ generate_cache(path)
28
+ end
31
29
  end
32
30
 
33
31
  ensure
34
32
  @page_render.close_connection
35
33
  end
34
+
35
+ private
36
+
37
+ def generate_cache(path, locale_domain = nil)
38
+ return if @page_caching.cache_exists?(path) && !@force_cache
39
+
40
+ url = @host + path
41
+ url += path.include?('?') ? '&' : '?'
42
+ url += "#{SeoCache.prerender_url_param}=true"
43
+
44
+ page_source = @page_render.get(url, false)
45
+ return unless page_source
46
+
47
+ @page_caching.cache(page_source, path, locale_domain)
48
+ end
36
49
  end
37
50
  end
@@ -1,3 +1,3 @@
1
1
  module SeoCache
2
- VERSION = '1.0.2'.freeze
2
+ VERSION = '1.0.6'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: seo_cache
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - FloXcoder
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-12-06 00:00:00.000000000 Z
11
+ date: 2021-07-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
@@ -229,7 +229,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
229
229
  - !ruby/object:Gem::Version
230
230
  version: '0'
231
231
  requirements: []
232
- rubygems_version: 3.0.8
232
+ rubygems_version: 3.2.17
233
233
  signing_key:
234
234
  specification_version: 4
235
235
  summary: Cache dedicated for SEO with Javascript rendering