jekyll 4.0.0.pre.alpha1 → 4.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +58 -17
  3. data/lib/jekyll.rb +5 -1
  4. data/lib/jekyll/cache.rb +71 -64
  5. data/lib/jekyll/cleaner.rb +5 -5
  6. data/lib/jekyll/collection.rb +6 -4
  7. data/lib/jekyll/command.rb +4 -2
  8. data/lib/jekyll/commands/new.rb +4 -4
  9. data/lib/jekyll/commands/serve.rb +9 -1
  10. data/lib/jekyll/commands/serve/servlet.rb +13 -14
  11. data/lib/jekyll/commands/serve/websockets.rb +1 -1
  12. data/lib/jekyll/configuration.rb +40 -129
  13. data/lib/jekyll/converters/identity.rb +2 -2
  14. data/lib/jekyll/converters/markdown/kramdown_parser.rb +70 -9
  15. data/lib/jekyll/convertible.rb +21 -20
  16. data/lib/jekyll/document.rb +56 -31
  17. data/lib/jekyll/drops/document_drop.rb +12 -0
  18. data/lib/jekyll/drops/drop.rb +14 -8
  19. data/lib/jekyll/drops/site_drop.rb +11 -1
  20. data/lib/jekyll/drops/url_drop.rb +52 -1
  21. data/lib/jekyll/entry_filter.rb +38 -44
  22. data/lib/jekyll/excerpt.rb +3 -3
  23. data/lib/jekyll/filters.rb +140 -22
  24. data/lib/jekyll/filters/url_filters.rb +41 -14
  25. data/lib/jekyll/frontmatter_defaults.rb +15 -20
  26. data/lib/jekyll/hooks.rb +2 -5
  27. data/lib/jekyll/inclusion.rb +32 -0
  28. data/lib/jekyll/liquid_renderer.rb +18 -15
  29. data/lib/jekyll/liquid_renderer/file.rb +10 -0
  30. data/lib/jekyll/liquid_renderer/table.rb +18 -61
  31. data/lib/jekyll/mime.types +53 -11
  32. data/lib/jekyll/page.rb +26 -2
  33. data/lib/jekyll/page_excerpt.rb +25 -0
  34. data/lib/jekyll/path_manager.rb +31 -0
  35. data/lib/jekyll/profiler.rb +58 -0
  36. data/lib/jekyll/reader.rb +4 -1
  37. data/lib/jekyll/readers/collection_reader.rb +1 -0
  38. data/lib/jekyll/readers/data_reader.rb +1 -0
  39. data/lib/jekyll/readers/layout_reader.rb +1 -0
  40. data/lib/jekyll/readers/page_reader.rb +5 -5
  41. data/lib/jekyll/readers/post_reader.rb +2 -1
  42. data/lib/jekyll/readers/static_file_reader.rb +3 -3
  43. data/lib/jekyll/readers/theme_assets_reader.rb +1 -0
  44. data/lib/jekyll/renderer.rb +9 -15
  45. data/lib/jekyll/site.rb +21 -12
  46. data/lib/jekyll/static_file.rb +15 -10
  47. data/lib/jekyll/tags/highlight.rb +2 -4
  48. data/lib/jekyll/tags/include.rb +67 -11
  49. data/lib/jekyll/tags/post_url.rb +8 -5
  50. data/lib/jekyll/theme.rb +19 -10
  51. data/lib/jekyll/url.rb +7 -3
  52. data/lib/jekyll/utils.rb +14 -18
  53. data/lib/jekyll/utils/platforms.rb +1 -1
  54. data/lib/jekyll/utils/win_tz.rb +1 -1
  55. data/lib/jekyll/version.rb +1 -1
  56. data/lib/theme_template/theme.gemspec.erb +1 -4
  57. metadata +33 -36
@@ -75,11 +75,13 @@ module Jekyll
75
75
  def entries
76
76
  return [] unless exists?
77
77
 
78
- @entries ||=
78
+ @entries ||= begin
79
+ collection_dir_slash = "#{collection_dir}/"
79
80
  Utils.safe_glob(collection_dir, ["**", "*"], File::FNM_DOTMATCH).map do |entry|
80
- entry["#{collection_dir}/"] = ""
81
+ entry[collection_dir_slash] = ""
81
82
  entry
82
83
  end
84
+ end
83
85
  end
84
86
 
85
87
  # Filtered version of the entries in this collection.
@@ -164,7 +166,7 @@ module Jekyll
164
166
  #
165
167
  # Returns a sanitized version of the label.
166
168
  def sanitize_label(label)
167
- label.gsub(%r![^a-z0-9_\-\.]!i, "")
169
+ label.gsub(%r![^a-z0-9_\-.]!i, "")
168
170
  end
169
171
 
170
172
  # Produce a representation of this Collection for use in Liquid.
@@ -237,7 +239,7 @@ module Jekyll
237
239
 
238
240
  # Fall back to `Document#<=>` if the properties were equal or were non-sortable
239
241
  # Otherwise continue with current sort-order
240
- if order.zero? || order.nil?
242
+ if order.nil? || order.zero?
241
243
  apples[-1] <=> olives[-1]
242
244
  else
243
245
  order
@@ -67,6 +67,8 @@ module Jekyll
67
67
  cmd.option "show_drafts", "-D", "--drafts", "Render posts in the _drafts folder"
68
68
  cmd.option "unpublished", "--unpublished",
69
69
  "Render posts that were marked as unpublished"
70
+ cmd.option "disable_disk_cache", "--disable-disk-cache",
71
+ "Disable caching to disk in non-safe mode"
70
72
  cmd.option "quiet", "-q", "--quiet", "Silence output."
71
73
  cmd.option "verbose", "-V", "--verbose", "Print verbose output."
72
74
  cmd.option "incremental", "-I", "--incremental", "Enable incremental rebuild."
@@ -84,7 +86,7 @@ module Jekyll
84
86
  # klass - an array of Jekyll::Command subclasses associated with the command
85
87
  #
86
88
  # Note that all exceptions are rescued..
87
- # rubocop: disable RescueException
89
+ # rubocop: disable Lint/RescueException
88
90
  def process_with_graceful_fail(cmd, options, *klass)
89
91
  klass.each { |k| k.process(options) if k.respond_to?(:process) }
90
92
  rescue Exception => e
@@ -97,7 +99,7 @@ module Jekyll
97
99
  Jekyll.logger.error "", " for any additional information or backtrace. "
98
100
  Jekyll.logger.abort_with "", dashes
99
101
  end
100
- # rubocop: enable RescueException
102
+ # rubocop: enable Lint/RescueException
101
103
  end
102
104
  end
103
105
  end
@@ -80,24 +80,24 @@ module Jekyll
80
80
  # Happy Jekylling!
81
81
  gem "jekyll", "~> #{Jekyll::VERSION}"
82
82
  # This is the default theme for new Jekyll sites. You may change this to anything you like.
83
- gem "minima", "~> 2.0"
83
+ gem "minima", "~> 2.5"
84
84
  # If you want to use GitHub Pages, remove the "gem "jekyll"" above and
85
85
  # uncomment the line below. To upgrade, run `bundle update github-pages`.
86
86
  # gem "github-pages", group: :jekyll_plugins
87
87
  # If you have any plugins, put them here!
88
88
  group :jekyll_plugins do
89
- gem "jekyll-feed", "~> 0.6"
89
+ gem "jekyll-feed", "~> 0.12"
90
90
  end
91
91
 
92
92
  # Windows and JRuby does not include zoneinfo files, so bundle the tzinfo-data gem
93
93
  # and associated library.
94
- install_if -> { RUBY_PLATFORM =~ %r!mingw|mswin|java! } do
94
+ platforms :mingw, :x64_mingw, :mswin, :jruby do
95
95
  gem "tzinfo", "~> 1.2"
96
96
  gem "tzinfo-data"
97
97
  end
98
98
 
99
99
  # Performance-booster for watching directories on Windows
100
- gem "wdm", "~> 0.1.1", :install_if => Gem.win_platform?
100
+ gem "wdm", "~> 0.1.1", :platforms => [:mingw, :x64_mingw, :mswin]
101
101
 
102
102
  RUBY
103
103
  end
@@ -307,7 +307,15 @@ module Jekyll
307
307
  require "webrick/https"
308
308
 
309
309
  opts[:SSLCertificate] = OpenSSL::X509::Certificate.new(read_file(src, cert))
310
- opts[:SSLPrivateKey] = OpenSSL::PKey::RSA.new(read_file(src, key))
310
+ begin
311
+ opts[:SSLPrivateKey] = OpenSSL::PKey::RSA.new(read_file(src, key))
312
+ rescue StandardError
313
+ if defined?(OpenSSL::PKey::EC)
314
+ opts[:SSLPrivateKey] = OpenSSL::PKey::EC.new(read_file(src, key))
315
+ else
316
+ raise
317
+ end
318
+ end
311
319
  opts[:SSLEnable] = true
312
320
  end
313
321
 
@@ -29,15 +29,15 @@ module Jekyll
29
29
  end
30
30
 
31
31
  def inline?
32
- @response["Content-Disposition"] =~ %r!^inline!
32
+ @response["Content-Disposition"].to_s.start_with?("inline")
33
33
  end
34
34
 
35
35
  def bad_browser?
36
- BAD_USER_AGENTS.any? { |pattern| @request["User-Agent"] =~ pattern }
36
+ BAD_USER_AGENTS.any? { |pattern| pattern.match?(@request["User-Agent"]) }
37
37
  end
38
38
 
39
39
  def html?
40
- @response["Content-Type"] =~ %r!text/html!
40
+ @response["Content-Type"].to_s.include?("text/html")
41
41
  end
42
42
  end
43
43
 
@@ -98,17 +98,16 @@ module Jekyll
98
98
  # Complicated JavaScript to ensure that livereload.js is loaded from the
99
99
  # same origin as the page. Mostly useful for dealing with the browser's
100
100
  # distinction between 'localhost' and 127.0.0.1
101
- template = <<-TEMPLATE
102
- <script>
103
- document.write(
104
- '<script src="http://' +
105
- (location.host || 'localhost').split(':')[0] +
106
- ':<%=@options["livereload_port"] %>/livereload.js?snipver=1<%= livereload_args %>"' +
107
- '></' +
108
- 'script>');
109
- </script>
101
+ @template ||= ERB.new(<<~TEMPLATE)
102
+ <script>
103
+ document.write(
104
+ '<script src="http://' +
105
+ (location.host || 'localhost').split(':')[0] +
106
+ ':<%=@options["livereload_port"] %>/livereload.js?snipver=1<%= livereload_args %>"' +
107
+ '></' +
108
+ 'script>');
109
+ </script>
110
110
  TEMPLATE
111
- ERB.new(Jekyll::Utils.strip_heredoc(template))
112
111
  end
113
112
 
114
113
  def livereload_args
@@ -186,7 +185,7 @@ module Jekyll
186
185
  key = res.header.keys.grep(%r!content-type!i).first
187
186
  typ = res.header[key]
188
187
 
189
- unless typ =~ %r!;\s*charset=!
188
+ unless %r!;\s*charset=!.match?(typ)
190
189
  res.header[key] = "#{typ}; charset=#{@jekyll_opts["encoding"]}"
191
190
  end
192
191
  end
@@ -46,7 +46,7 @@ module Jekyll
46
46
  # WebSockets requests will have a Connection: Upgrade header
47
47
  if parser.http_method != "GET" || parser.upgrade?
48
48
  super
49
- elsif parser.request_url =~ %r!^\/livereload.js!
49
+ elsif parser.request_url.start_with?("/livereload.js")
50
50
  headers = [
51
51
  "HTTP/1.1 200 OK",
52
52
  "Content-Type: application/javascript",
@@ -4,7 +4,7 @@ module Jekyll
4
4
  class Configuration < Hash
5
5
  # Default options. Overridden by values in _config.yml.
6
6
  # Strings rather than symbols are used for compatibility with YAML.
7
- DEFAULTS = Configuration[{
7
+ DEFAULTS = {
8
8
  # Where things are
9
9
  "source" => Dir.pwd,
10
10
  "destination" => File.join(Dir.pwd, "_site"),
@@ -66,7 +66,7 @@ module Jekyll
66
66
 
67
67
  "kramdown" => {
68
68
  "auto_ids" => true,
69
- "toc_levels" => "1..6",
69
+ "toc_levels" => (1..6).to_a,
70
70
  "entity_output" => "as_char",
71
71
  "smart_quotes" => "lsquo,rsquo,ldquo,rdquo",
72
72
  "input" => "GFM",
@@ -75,19 +75,15 @@ module Jekyll
75
75
  "footnote_nr" => 1,
76
76
  "show_warnings" => false,
77
77
  },
78
- }.map { |k, v| [k, v.freeze] }].freeze
78
+ }.each_with_object(Configuration.new) { |(k, v), hsh| hsh[k] = v.freeze }.freeze
79
79
 
80
80
  class << self
81
81
  # Static: Produce a Configuration ready for use in a Site.
82
- # It takes the input, fills in the defaults where values do not
83
- # exist, and patches common issues including migrating options for
84
- # backwards compatiblity. Except where a key or value is being fixed,
85
- # the user configuration will override the defaults.
82
+ # It takes the input, fills in the defaults where values do not exist.
86
83
  #
87
84
  # user_config - a Hash or Configuration of overrides.
88
85
  #
89
- # Returns a Configuration filled with defaults and fixed for common
90
- # problems and backwards-compatibility.
86
+ # Returns a Configuration filled with defaults.
91
87
  def from(user_config)
92
88
  Utils.deep_merge_hashes(DEFAULTS, Configuration[user_config].stringify_keys)
93
89
  .add_default_collections.add_default_excludes
@@ -98,7 +94,7 @@ module Jekyll
98
94
  #
99
95
  # Return a copy of the hash where all its keys are strings
100
96
  def stringify_keys
101
- reduce({}) { |hsh, (k, v)| hsh.merge(k.to_s => v) }
97
+ each_with_object({}) { |(k, v), hsh| hsh[k.to_s] = v }
102
98
  end
103
99
 
104
100
  def get_config_value_with_override(config_key, override)
@@ -132,8 +128,8 @@ module Jekyll
132
128
  when %r!\.ya?ml!i
133
129
  SafeYAML.load_file(filename) || {}
134
130
  else
135
- raise ArgumentError, "No parser for '#{filename}' is available.
136
- Use a .y(a)ml or .toml file instead."
131
+ raise ArgumentError,
132
+ "No parser for '#{filename}' is available. Use a .y(a)ml or .toml file instead."
137
133
  end
138
134
  end
139
135
 
@@ -169,7 +165,11 @@ module Jekyll
169
165
  def read_config_file(file)
170
166
  file = File.expand_path(file)
171
167
  next_config = safe_load_file(file)
172
- check_config_is_hash!(next_config, file)
168
+
169
+ unless next_config.is_a?(Hash)
170
+ raise ArgumentError, "Configuration file: (INVALID) #{file}".yellow
171
+ end
172
+
173
173
  Jekyll.logger.info "Configuration file:", file
174
174
  next_config
175
175
  rescue SystemCallError
@@ -177,8 +177,7 @@ module Jekyll
177
177
  Jekyll.logger.warn "Configuration file:", "none"
178
178
  {}
179
179
  else
180
- Jekyll.logger.error "Fatal:", "The configuration file '#{file}'
181
- could not be found."
180
+ Jekyll.logger.error "Fatal:", "The configuration file '#{file}' could not be found."
182
181
  raise LoadError, "The Configuration file '#{file}' could not be found."
183
182
  end
184
183
  end
@@ -199,13 +198,12 @@ module Jekyll
199
198
  new_config = read_config_file(config_file)
200
199
  configuration = Utils.deep_merge_hashes(configuration, new_config)
201
200
  end
202
- rescue ArgumentError => err
203
- Jekyll.logger.warn "WARNING:", "Error reading configuration. " \
204
- "Using defaults (and options)."
205
- warn err
201
+ rescue ArgumentError => e
202
+ Jekyll.logger.warn "WARNING:", "Error reading configuration. Using defaults (and options)."
203
+ warn e
206
204
  end
207
205
 
208
- configuration.backwards_compatibilize.add_default_collections
206
+ configuration.validate.add_default_collections
209
207
  end
210
208
 
211
209
  # Public: Split a CSV string into an array containing its values
@@ -217,35 +215,18 @@ module Jekyll
217
215
  csv.split(",").map(&:strip)
218
216
  end
219
217
 
220
- # Public: Ensure the proper options are set in the configuration to allow for
221
- # backwards-compatibility with Jekyll pre-1.0
218
+ # Public: Ensure the proper options are set in the configuration
222
219
  #
223
- # Returns the backwards-compatible configuration
224
- def backwards_compatibilize
220
+ # Returns the configuration Hash
221
+ def validate
225
222
  config = clone
226
- # Provide backwards-compatibility
227
- check_auto(config)
228
- check_server(config)
229
- check_plugins(config)
230
223
 
231
- renamed_key "server_port", "port", config
232
- renamed_key "gems", "plugins", config
233
- renamed_key "layouts", "layouts_dir", config
234
- renamed_key "data_source", "data_dir", config
235
-
236
- check_pygments(config)
224
+ check_plugins(config)
237
225
  check_include_exclude(config)
238
- check_coderay(config)
239
- check_maruku(config)
240
226
 
241
227
  config
242
228
  end
243
229
 
244
- # DEPRECATED.
245
- def fix_common_issues
246
- self
247
- end
248
-
249
230
  def add_default_collections
250
231
  config = clone
251
232
 
@@ -254,7 +235,9 @@ module Jekyll
254
235
 
255
236
  # Ensure we have a hash.
256
237
  if config["collections"].is_a?(Array)
257
- config["collections"] = Hash[config["collections"].map { |c| [c, {}] }]
238
+ config["collections"] = config["collections"].each_with_object({}) do |collection, hash|
239
+ hash[collection] = {}
240
+ end
258
241
  end
259
242
 
260
243
  config["collections"] = Utils.deep_merge_hashes(
@@ -284,15 +267,6 @@ module Jekyll
284
267
  config
285
268
  end
286
269
 
287
- def renamed_key(old, new, config)
288
- if config.key?(old)
289
- Jekyll::Deprecator.deprecation_message "The '#{old}' configuration" \
290
- " option has been renamed to '#{new}'. Please update your config" \
291
- " file accordingly."
292
- config[new] = config.delete(old)
293
- end
294
- end
295
-
296
270
  private
297
271
 
298
272
  def style_to_permalink(permalink_style)
@@ -305,82 +279,20 @@ module Jekyll
305
279
  "/:categories/:year/:month/:day/:title:output_ext"
306
280
  when :ordinal
307
281
  "/:categories/:year/:y_day/:title:output_ext"
282
+ when :weekdate
283
+ "/:categories/:year/W:week/:short_day/:title:output_ext"
308
284
  else
309
285
  permalink_style.to_s
310
286
  end
311
287
  end
312
288
 
313
- # Private: Checks if a given config is a hash
314
- #
315
- # extracted_config - the value to check
316
- # file - the file from which the config was extracted
317
- #
318
- # Raises an ArgumentError if given config is not a hash
319
- def check_config_is_hash!(extracted_config, file)
320
- unless extracted_config.is_a?(Hash)
321
- raise ArgumentError, "Configuration file: (INVALID) #{file}".yellow
322
- end
323
- end
324
-
325
- def check_auto(config)
326
- if config.key?("auto") || config.key?("watch")
327
- Jekyll::Deprecator.deprecation_message "Auto-regeneration can no longer" \
328
- " be set from your configuration file(s). Use the" \
329
- " --[no-]watch/-w command-line option instead."
330
- config.delete("auto")
331
- config.delete("watch")
332
- end
333
- end
334
-
335
- def check_server(config)
336
- if config.key?("server")
337
- Jekyll::Deprecator.deprecation_message "The 'server' configuration option" \
338
- " is no longer accepted. Use the 'jekyll serve'" \
339
- " subcommand to serve your site with WEBrick."
340
- config.delete("server")
341
- end
342
- end
343
-
344
- def check_pygments(config)
345
- if config.key?("pygments")
346
- Jekyll::Deprecator.deprecation_message "The 'pygments' configuration option" \
347
- " has been renamed to 'highlighter'. Please update your" \
348
- " config file accordingly. The allowed values are 'rouge', " \
349
- "'pygments' or null."
350
-
351
- config["highlighter"] = "pygments" if config["pygments"]
352
- config.delete("pygments")
353
- end
354
- end
355
-
356
289
  def check_include_exclude(config)
357
290
  %w(include exclude).each do |option|
358
- if config[option].is_a?(String)
359
- Jekyll::Deprecator.deprecation_message "The '#{option}' configuration option" \
360
- " must now be specified as an array, but you specified" \
361
- " a string. For now, we've treated the string you provided" \
362
- " as a list of comma-separated values."
363
- config[option] = csv_to_array(config[option])
364
- end
365
- config[option]&.map!(&:to_s)
366
- end
367
- end
291
+ next unless config.key?(option)
292
+ next if config[option].is_a?(Array)
368
293
 
369
- def check_coderay(config)
370
- if (config["kramdown"] || {}).key?("use_coderay")
371
- Jekyll::Deprecator.deprecation_message "Please change 'use_coderay'" \
372
- " to 'enable_coderay' in your configuration file."
373
- config["kramdown"]["use_coderay"] = config["kramdown"].delete("enable_coderay")
374
- end
375
- end
376
-
377
- def check_maruku(config)
378
- if config.fetch("markdown", "kramdown").to_s.casecmp("maruku").zero?
379
- Jekyll.logger.abort_with "Error:", "You're using the 'maruku' " \
380
- "Markdown processor, which has been removed as of 3.0.0. " \
381
- "We recommend you switch to Kramdown. To do this, replace " \
382
- "`markdown: maruku` with `markdown: kramdown` in your " \
383
- "`_config.yml` file."
294
+ raise Jekyll::Errors::InvalidConfigurationError,
295
+ "'#{option}' should be set as an array, but was: #{config[option].inspect}."
384
296
  end
385
297
  end
386
298
 
@@ -389,17 +301,16 @@ module Jekyll
389
301
  # config - the config hash
390
302
  #
391
303
  # Raises a Jekyll::Errors::InvalidConfigurationError if the config `plugins`
392
- # is a string
304
+ # is not an Array.
393
305
  def check_plugins(config)
394
- if config.key?("plugins") && config["plugins"].is_a?(String)
395
- Jekyll.logger.error "Configuration Error:", "You specified the" \
396
- " `plugins` config in your configuration file as a string, please" \
397
- " use an array instead. If you wanted to set the directory of your" \
398
- " plugins, use the config key `plugins_dir` instead."
399
- raise Jekyll::Errors::InvalidConfigurationError,
400
- "'plugins' should not be a string, but was: " \
401
- "#{config["plugins"].inspect}. Use 'plugins_dir' instead."
402
- end
306
+ return unless config.key?("plugins")
307
+ return if config["plugins"].is_a?(Array)
308
+
309
+ Jekyll.logger.error "'plugins' should be set as an array of gem-names, but was: " \
310
+ "#{config["plugins"].inspect}. Use 'plugins_dir' instead to set the directory " \
311
+ "for your non-gemified Ruby plugins."
312
+ raise Jekyll::Errors::InvalidConfigurationError,
313
+ "'plugins' should be set as an array, but was: #{config["plugins"].inspect}."
403
314
  end
404
315
  end
405
316
  end