jekyll 3.2.0.pre.beta1 → 3.2.0.pre.beta2
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of jekyll might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/.rubocop.yml +17 -95
- data/README.markdown +6 -4
- data/{bin → exe}/jekyll +18 -14
- data/lib/jekyll.rb +79 -76
- data/lib/jekyll/collection.rb +32 -16
- data/lib/jekyll/command.rb +17 -13
- data/lib/jekyll/commands/build.rb +7 -2
- data/lib/jekyll/commands/doctor.rb +3 -1
- data/lib/jekyll/commands/new.rb +3 -0
- data/lib/jekyll/commands/new_theme.rb +7 -4
- data/lib/jekyll/commands/serve.rb +2 -0
- data/lib/jekyll/commands/serve/servlet.rb +2 -2
- data/lib/jekyll/configuration.rb +187 -125
- data/lib/jekyll/converters/markdown.rb +19 -9
- data/lib/jekyll/converters/markdown/kramdown_parser.rb +12 -5
- data/lib/jekyll/converters/markdown/rdiscount_parser.rb +4 -4
- data/lib/jekyll/converters/markdown/redcarpet_parser.rb +90 -84
- data/lib/jekyll/convertible.rb +34 -21
- data/lib/jekyll/deprecator.rb +11 -6
- data/lib/jekyll/document.rb +52 -50
- data/lib/jekyll/drops/document_drop.rb +40 -5
- data/lib/jekyll/drops/drop.rb +49 -10
- data/lib/jekyll/drops/excerpt_drop.rb +15 -0
- data/lib/jekyll/drops/jekyll_drop.rb +12 -0
- data/lib/jekyll/drops/site_drop.rb +4 -2
- data/lib/jekyll/drops/url_drop.rb +4 -4
- data/lib/jekyll/entry_filter.rb +9 -6
- data/lib/jekyll/errors.rb +4 -3
- data/lib/jekyll/excerpt.rb +4 -6
- data/lib/jekyll/external.rb +4 -4
- data/lib/jekyll/filters.rb +67 -34
- data/lib/jekyll/frontmatter_defaults.rb +45 -38
- data/lib/jekyll/hooks.rb +21 -21
- data/lib/jekyll/layout.rb +3 -1
- data/lib/jekyll/liquid_renderer.rb +7 -3
- data/lib/jekyll/liquid_renderer/file.rb +1 -1
- data/lib/jekyll/liquid_renderer/table.rb +11 -11
- data/lib/jekyll/log_adapter.rb +2 -2
- data/lib/jekyll/page.rb +10 -10
- data/lib/jekyll/plugin.rb +5 -5
- data/lib/jekyll/plugin_manager.rb +12 -8
- data/lib/jekyll/publisher.rb +1 -1
- data/lib/jekyll/reader.rb +11 -7
- data/lib/jekyll/readers/data_reader.rb +9 -9
- data/lib/jekyll/readers/layout_reader.rb +7 -7
- data/lib/jekyll/readers/page_reader.rb +3 -1
- data/lib/jekyll/readers/post_reader.rb +9 -10
- data/lib/jekyll/readers/static_file_reader.rb +3 -1
- data/lib/jekyll/regenerator.rb +50 -28
- data/lib/jekyll/related_posts.rb +1 -1
- data/lib/jekyll/renderer.rb +29 -20
- data/lib/jekyll/site.rb +92 -50
- data/lib/jekyll/static_file.rb +33 -26
- data/lib/jekyll/stevenson.rb +6 -5
- data/lib/jekyll/tags/highlight.rb +50 -35
- data/lib/jekyll/tags/include.rb +42 -31
- data/lib/jekyll/tags/link.rb +11 -4
- data/lib/jekyll/tags/post_url.rb +8 -7
- data/lib/jekyll/theme.rb +4 -3
- data/lib/jekyll/theme_builder.rb +18 -6
- data/lib/jekyll/url.rb +21 -14
- data/lib/jekyll/utils.rb +57 -28
- data/lib/jekyll/utils/ansi.rb +9 -9
- data/lib/jekyll/utils/platforms.rb +2 -2
- data/lib/jekyll/version.rb +1 -1
- data/lib/site_template/_config.yml +2 -0
- data/lib/site_template/css/main.scss +3 -17
- data/lib/theme_template/_layouts/default.html +1 -0
- data/lib/theme_template/_layouts/page.html +5 -0
- data/lib/theme_template/_layouts/post.html +5 -0
- data/lib/theme_template/example/_post.md +1 -2
- data/lib/theme_template/example/index.html +2 -2
- data/lib/theme_template/gitignore.erb +4 -0
- data/lib/theme_template/theme.gemspec.erb +2 -6
- metadata +10 -18
- data/lib/site_template/_includes/footer.html +0 -38
- data/lib/site_template/_includes/head.html +0 -12
- data/lib/site_template/_includes/header.html +0 -27
- data/lib/site_template/_includes/icon-github.html +0 -1
- data/lib/site_template/_includes/icon-github.svg +0 -1
- data/lib/site_template/_includes/icon-twitter.html +0 -1
- data/lib/site_template/_includes/icon-twitter.svg +0 -1
- data/lib/site_template/_layouts/default.html +0 -20
- data/lib/site_template/_layouts/page.html +0 -14
- data/lib/site_template/_layouts/post.html +0 -15
- data/lib/site_template/_sass/_base.scss +0 -200
- data/lib/site_template/_sass/_layout.scss +0 -242
- data/lib/site_template/_sass/_syntax-highlighting.scss +0 -71
@@ -16,6 +16,18 @@ module Jekyll
|
|
16
16
|
def environment
|
17
17
|
Jekyll.env
|
18
18
|
end
|
19
|
+
|
20
|
+
def to_h
|
21
|
+
@to_h ||= {
|
22
|
+
"version" => version,
|
23
|
+
"environment" => environment
|
24
|
+
}
|
25
|
+
end
|
26
|
+
|
27
|
+
def to_json(state = nil)
|
28
|
+
require "json"
|
29
|
+
JSON.generate(to_h, state)
|
30
|
+
end
|
19
31
|
end
|
20
32
|
end
|
21
33
|
end
|
@@ -24,11 +24,13 @@ module Jekyll
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def html_pages
|
27
|
-
@site_html_pages ||= @obj.pages.select
|
27
|
+
@site_html_pages ||= @obj.pages.select do |page|
|
28
|
+
page.html? || page.url.end_with?("/")
|
29
|
+
end
|
28
30
|
end
|
29
31
|
|
30
32
|
def collections
|
31
|
-
@site_collections ||= @obj.collections.values.map(&:to_liquid)
|
33
|
+
@site_collections ||= @obj.collections.values.sort_by(&:label).map(&:to_liquid)
|
32
34
|
end
|
33
35
|
|
34
36
|
private
|
@@ -19,20 +19,20 @@ module Jekyll
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def title
|
22
|
-
Utils.slugify(@obj.data[
|
22
|
+
Utils.slugify(@obj.data["slug"], :mode => "pretty", :cased => true) ||
|
23
23
|
Utils.slugify(@obj.basename_without_ext, :mode => "pretty", :cased => true)
|
24
24
|
end
|
25
25
|
|
26
26
|
def slug
|
27
|
-
Utils.slugify(@obj.data[
|
27
|
+
Utils.slugify(@obj.data["slug"]) || Utils.slugify(@obj.basename_without_ext)
|
28
28
|
end
|
29
29
|
|
30
30
|
def categories
|
31
31
|
category_set = Set.new
|
32
|
-
Array(@obj.data[
|
32
|
+
Array(@obj.data["categories"]).each do |category|
|
33
33
|
category_set << category.to_s.downcase
|
34
34
|
end
|
35
|
-
category_set.to_a.join(
|
35
|
+
category_set.to_a.join("/")
|
36
36
|
end
|
37
37
|
|
38
38
|
def year
|
data/lib/jekyll/entry_filter.rb
CHANGED
@@ -2,7 +2,7 @@ module Jekyll
|
|
2
2
|
class EntryFilter
|
3
3
|
attr_reader :site
|
4
4
|
SPECIAL_LEADING_CHARACTERS = [
|
5
|
-
|
5
|
+
".", "_", "#", "~"
|
6
6
|
].freeze
|
7
7
|
|
8
8
|
def initialize(site, base_directory = nil)
|
@@ -37,8 +37,7 @@ module Jekyll
|
|
37
37
|
|
38
38
|
def included?(entry)
|
39
39
|
glob_include?(site.include,
|
40
|
-
entry
|
41
|
-
)
|
40
|
+
entry)
|
42
41
|
end
|
43
42
|
|
44
43
|
def special?(entry)
|
@@ -47,12 +46,17 @@ module Jekyll
|
|
47
46
|
end
|
48
47
|
|
49
48
|
def backup?(entry)
|
50
|
-
entry[-1..-1] ==
|
49
|
+
entry[-1..-1] == "~"
|
51
50
|
end
|
52
51
|
|
53
52
|
def excluded?(entry)
|
54
53
|
excluded = glob_include?(site.exclude, relative_to_source(entry))
|
55
|
-
|
54
|
+
if excluded
|
55
|
+
Jekyll.logger.debug(
|
56
|
+
"EntryFilter:",
|
57
|
+
"excluded #{relative_to_source(entry)}"
|
58
|
+
)
|
59
|
+
end
|
56
60
|
excluded
|
57
61
|
end
|
58
62
|
|
@@ -83,7 +87,6 @@ module Jekyll
|
|
83
87
|
def glob_include?(enum, e)
|
84
88
|
entry = Pathutil.new(site.in_source_dir).join(e)
|
85
89
|
enum.any? do |exp|
|
86
|
-
|
87
90
|
# Users who send a Regexp knows what they want to
|
88
91
|
# exclude, so let them send a Regexp to exclude files,
|
89
92
|
# we will not bother caring if it works or not, it's
|
data/lib/jekyll/errors.rb
CHANGED
@@ -9,8 +9,9 @@ module Jekyll
|
|
9
9
|
InvalidYAMLFrontMatterError = Class.new(FatalException)
|
10
10
|
MissingDependencyException = Class.new(FatalException)
|
11
11
|
|
12
|
-
InvalidDateError
|
13
|
-
InvalidPostNameError
|
14
|
-
PostURLError
|
12
|
+
InvalidDateError = Class.new(FatalException)
|
13
|
+
InvalidPostNameError = Class.new(FatalException)
|
14
|
+
PostURLError = Class.new(FatalException)
|
15
|
+
InvalidURLError = Class.new(FatalException)
|
15
16
|
end
|
16
17
|
end
|
data/lib/jekyll/excerpt.rb
CHANGED
@@ -7,7 +7,8 @@ module Jekyll
|
|
7
7
|
attr_writer :output
|
8
8
|
|
9
9
|
def_delegators :@doc, :site, :name, :ext, :relative_path, :extname,
|
10
|
-
:render_with_liquid?, :collection, :related_posts
|
10
|
+
:render_with_liquid?, :collection, :related_posts,
|
11
|
+
:url, :next_doc, :previous_doc
|
11
12
|
|
12
13
|
# Initialize this Excerpt instance.
|
13
14
|
#
|
@@ -59,10 +60,7 @@ module Jekyll
|
|
59
60
|
end
|
60
61
|
|
61
62
|
def to_liquid
|
62
|
-
|
63
|
-
@to_liquid ||= doc.to_liquid
|
64
|
-
doc.data['excerpt'] = self
|
65
|
-
@to_liquid
|
63
|
+
Jekyll::Drops::ExcerptDrop.new(self)
|
66
64
|
end
|
67
65
|
|
68
66
|
# Returns the shorthand String identifier of this doc.
|
@@ -120,7 +118,7 @@ module Jekyll
|
|
120
118
|
if tail.empty?
|
121
119
|
head
|
122
120
|
else
|
123
|
-
"" << head << "\n\n" << tail.scan(
|
121
|
+
"" << head << "\n\n" << tail.scan(%r!^\[[^\]]+\]:.+$!).join("\n")
|
124
122
|
end
|
125
123
|
end
|
126
124
|
end
|
data/lib/jekyll/external.rb
CHANGED
@@ -17,13 +17,13 @@ module Jekyll
|
|
17
17
|
#
|
18
18
|
# names - a string gem name or array of gem names
|
19
19
|
#
|
20
|
-
def require_if_present(names
|
20
|
+
def require_if_present(names)
|
21
21
|
Array(names).each do |name|
|
22
22
|
begin
|
23
23
|
require name
|
24
24
|
rescue LoadError
|
25
25
|
Jekyll.logger.debug "Couldn't load #{name}. Skipping."
|
26
|
-
|
26
|
+
yield(name) if block_given?
|
27
27
|
false
|
28
28
|
end
|
29
29
|
end
|
@@ -39,7 +39,7 @@ module Jekyll
|
|
39
39
|
def require_with_graceful_fail(names)
|
40
40
|
Array(names).each do |name|
|
41
41
|
begin
|
42
|
-
Jekyll.logger.debug "Requiring:",
|
42
|
+
Jekyll.logger.debug "Requiring:", name.to_s
|
43
43
|
require name
|
44
44
|
rescue LoadError => e
|
45
45
|
Jekyll.logger.error "Dependency Error:", <<-MSG
|
@@ -50,7 +50,7 @@ The full error message from Ruby is: '#{e.message}'
|
|
50
50
|
|
51
51
|
If you run into trouble, you can find helpful resources at http://jekyllrb.com/help/!
|
52
52
|
MSG
|
53
|
-
raise Jekyll::Errors::MissingDependencyException
|
53
|
+
raise Jekyll::Errors::MissingDependencyException, name
|
54
54
|
end
|
55
55
|
end
|
56
56
|
end
|
data/lib/jekyll/filters.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
1
|
+
require "uri"
|
2
|
+
require "json"
|
3
|
+
require "date"
|
4
|
+
require "liquid"
|
5
5
|
|
6
6
|
module Jekyll
|
7
7
|
module Filters
|
@@ -13,7 +13,7 @@ module Jekyll
|
|
13
13
|
def markdownify(input)
|
14
14
|
site = @context.registers[:site]
|
15
15
|
converter = site.find_converter_instance(Jekyll::Converters::Markdown)
|
16
|
-
converter.convert(input)
|
16
|
+
converter.convert(input.to_s)
|
17
17
|
end
|
18
18
|
|
19
19
|
# Convert quotes into smart quotes.
|
@@ -24,7 +24,7 @@ module Jekyll
|
|
24
24
|
def smartify(input)
|
25
25
|
site = @context.registers[:site]
|
26
26
|
converter = site.find_converter_instance(Jekyll::Converters::SmartyPants)
|
27
|
-
converter.convert(input)
|
27
|
+
converter.convert(input.to_s)
|
28
28
|
end
|
29
29
|
|
30
30
|
# Convert a Sass string into CSS output.
|
@@ -56,7 +56,7 @@ module Jekyll
|
|
56
56
|
#
|
57
57
|
# Returns the given filename or title as a lowercase URL String.
|
58
58
|
# See Utils.slugify for more detail.
|
59
|
-
def slugify(input, mode=nil)
|
59
|
+
def slugify(input, mode = nil)
|
60
60
|
Utils.slugify(input, :mode => mode)
|
61
61
|
end
|
62
62
|
|
@@ -118,7 +118,7 @@ module Jekyll
|
|
118
118
|
#
|
119
119
|
# Returns the escaped String.
|
120
120
|
def xml_escape(input)
|
121
|
-
input.to_s.encode(:xml => :attr).gsub(
|
121
|
+
input.to_s.encode(:xml => :attr).gsub(%r!\A"|"\Z!, "")
|
122
122
|
end
|
123
123
|
|
124
124
|
# CGI escape a string for use in a URL. Replaces any special characters
|
@@ -133,7 +133,7 @@ module Jekyll
|
|
133
133
|
#
|
134
134
|
# Returns the escaped String.
|
135
135
|
def cgi_escape(input)
|
136
|
-
CGI
|
136
|
+
CGI.escape(input)
|
137
137
|
end
|
138
138
|
|
139
139
|
# URI escape a string.
|
@@ -150,6 +150,15 @@ module Jekyll
|
|
150
150
|
URI.escape(input)
|
151
151
|
end
|
152
152
|
|
153
|
+
# Replace any whitespace in the input string with a single space
|
154
|
+
#
|
155
|
+
# input - The String on which to operate.
|
156
|
+
#
|
157
|
+
# Returns the formatted String
|
158
|
+
def normalize_whitespace(input)
|
159
|
+
input.to_s.gsub(%r!\s+!, " ").strip
|
160
|
+
end
|
161
|
+
|
153
162
|
# Count the number of words in the input string.
|
154
163
|
#
|
155
164
|
# input - The String on which to operate.
|
@@ -180,7 +189,7 @@ module Jekyll
|
|
180
189
|
when 2
|
181
190
|
"#{array[0]} #{connector} #{array[1]}"
|
182
191
|
else
|
183
|
-
"#{array[0...-1].join(
|
192
|
+
"#{array[0...-1].join(", ")}, #{connector} #{array[-1]}"
|
184
193
|
end
|
185
194
|
end
|
186
195
|
|
@@ -203,11 +212,14 @@ module Jekyll
|
|
203
212
|
# "items" => [...] } # all the items where `property` == "larry"
|
204
213
|
def group_by(input, property)
|
205
214
|
if groupable?(input)
|
206
|
-
input.group_by
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
215
|
+
input.group_by { |item| item_property(item, property).to_s }
|
216
|
+
.each_with_object([]) do |item, array|
|
217
|
+
array << {
|
218
|
+
"name" => item.first,
|
219
|
+
"items" => item.last,
|
220
|
+
"size" => item.last.size
|
221
|
+
}
|
222
|
+
end
|
211
223
|
else
|
212
224
|
input
|
213
225
|
end
|
@@ -223,7 +235,9 @@ module Jekyll
|
|
223
235
|
def where(input, property, value)
|
224
236
|
return input unless input.is_a?(Enumerable)
|
225
237
|
input = input.values if input.is_a?(Hash)
|
226
|
-
input.select
|
238
|
+
input.select do |object|
|
239
|
+
Array(item_property(object, property)).map(&:to_s).include?(value.to_s)
|
240
|
+
end
|
227
241
|
end
|
228
242
|
|
229
243
|
# Filters an array of objects against an expression
|
@@ -246,6 +260,17 @@ module Jekyll
|
|
246
260
|
end
|
247
261
|
end
|
248
262
|
|
263
|
+
# Convert the input into integer
|
264
|
+
#
|
265
|
+
# input - the object string
|
266
|
+
#
|
267
|
+
# Returns the integer value
|
268
|
+
def to_integer(input)
|
269
|
+
return 1 if input == true
|
270
|
+
return 0 if input == false
|
271
|
+
input.to_i
|
272
|
+
end
|
273
|
+
|
249
274
|
# Sort an array of objects
|
250
275
|
#
|
251
276
|
# input - the object array
|
@@ -255,33 +280,21 @@ module Jekyll
|
|
255
280
|
# Returns the filtered array of objects
|
256
281
|
def sort(input, property = nil, nils = "first")
|
257
282
|
if input.nil?
|
258
|
-
raise ArgumentError
|
283
|
+
raise ArgumentError, "Cannot sort a null object."
|
259
284
|
end
|
260
285
|
if property.nil?
|
261
286
|
input.sort
|
262
287
|
else
|
263
|
-
|
264
|
-
when nils == "first"
|
288
|
+
if nils == "first"
|
265
289
|
order = - 1
|
266
|
-
|
290
|
+
elsif nils == "last"
|
267
291
|
order = + 1
|
268
292
|
else
|
269
|
-
raise ArgumentError
|
270
|
-
"'#{nils}' is not a valid nils order. It must be 'first' or 'last'."
|
293
|
+
raise ArgumentError, "Invalid nils order: " \
|
294
|
+
"'#{nils}' is not a valid nils order. It must be 'first' or 'last'."
|
271
295
|
end
|
272
296
|
|
273
|
-
input
|
274
|
-
apple_property = item_property(apple, property)
|
275
|
-
orange_property = item_property(orange, property)
|
276
|
-
|
277
|
-
if !apple_property.nil? && orange_property.nil?
|
278
|
-
- order
|
279
|
-
elsif apple_property.nil? && !orange_property.nil?
|
280
|
-
+ order
|
281
|
-
else
|
282
|
-
apple_property <=> orange_property
|
283
|
-
end
|
284
|
-
end
|
297
|
+
sort_input(input, property, order)
|
285
298
|
end
|
286
299
|
end
|
287
300
|
|
@@ -332,6 +345,22 @@ module Jekyll
|
|
332
345
|
xml_escape(input.inspect)
|
333
346
|
end
|
334
347
|
|
348
|
+
private
|
349
|
+
def sort_input(input, property, order)
|
350
|
+
input.sort do |apple, orange|
|
351
|
+
apple_property = item_property(apple, property)
|
352
|
+
orange_property = item_property(orange, property)
|
353
|
+
|
354
|
+
if !apple_property.nil? && orange_property.nil?
|
355
|
+
- order
|
356
|
+
elsif apple_property.nil? && !orange_property.nil?
|
357
|
+
+ order
|
358
|
+
else
|
359
|
+
apple_property <=> orange_property
|
360
|
+
end
|
361
|
+
end
|
362
|
+
end
|
363
|
+
|
335
364
|
private
|
336
365
|
def time(input)
|
337
366
|
case input
|
@@ -349,10 +378,12 @@ module Jekyll
|
|
349
378
|
end.localtime
|
350
379
|
end
|
351
380
|
|
381
|
+
private
|
352
382
|
def groupable?(element)
|
353
383
|
element.respond_to?(:group_by)
|
354
384
|
end
|
355
385
|
|
386
|
+
private
|
356
387
|
def item_property(item, property)
|
357
388
|
if item.respond_to?(:to_liquid)
|
358
389
|
item.to_liquid[property.to_s]
|
@@ -363,6 +394,7 @@ module Jekyll
|
|
363
394
|
end
|
364
395
|
end
|
365
396
|
|
397
|
+
private
|
366
398
|
def as_liquid(item)
|
367
399
|
case item
|
368
400
|
when Hash
|
@@ -386,6 +418,7 @@ module Jekyll
|
|
386
418
|
end
|
387
419
|
|
388
420
|
# Parse a string to a Liquid Condition
|
421
|
+
private
|
389
422
|
def parse_condition(exp)
|
390
423
|
parser = Liquid::Parser.new(exp)
|
391
424
|
left_expr = parser.expression
|
@@ -11,37 +11,42 @@ module Jekyll
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def update_deprecated_types(set)
|
14
|
-
return set unless set.key?(
|
15
|
-
|
16
|
-
set[
|
17
|
-
case set[
|
18
|
-
when
|
19
|
-
Deprecator.defaults_deprecate_type(
|
20
|
-
|
21
|
-
when
|
22
|
-
Deprecator.defaults_deprecate_type(
|
23
|
-
|
24
|
-
when
|
25
|
-
Deprecator.defaults_deprecate_type(
|
26
|
-
|
14
|
+
return set unless set.key?("scope") && set["scope"].key?("type")
|
15
|
+
|
16
|
+
set["scope"]["type"] =
|
17
|
+
case set["scope"]["type"]
|
18
|
+
when "page"
|
19
|
+
Deprecator.defaults_deprecate_type("page", "pages")
|
20
|
+
"pages"
|
21
|
+
when "post"
|
22
|
+
Deprecator.defaults_deprecate_type("post", "posts")
|
23
|
+
"posts"
|
24
|
+
when "draft"
|
25
|
+
Deprecator.defaults_deprecate_type("draft", "drafts")
|
26
|
+
"drafts"
|
27
27
|
else
|
28
|
-
set[
|
28
|
+
set["scope"]["type"]
|
29
29
|
end
|
30
30
|
|
31
31
|
set
|
32
32
|
end
|
33
33
|
|
34
34
|
def ensure_time!(set)
|
35
|
-
return set unless set.key?(
|
36
|
-
return set if set[
|
37
|
-
set[
|
35
|
+
return set unless set.key?("values") && set["values"].key?("date")
|
36
|
+
return set if set["values"]["date"].is_a?(Time)
|
37
|
+
set["values"]["date"] = Utils.parse_date(
|
38
|
+
set["values"]["date"],
|
39
|
+
"An invalid date format was found in a front-matter default set: #{set}"
|
40
|
+
)
|
38
41
|
set
|
39
42
|
end
|
40
43
|
|
41
44
|
# Finds a default value for a given setting, filtered by path and type
|
42
45
|
#
|
43
|
-
# path - the path (relative to the source) of the page,
|
44
|
-
#
|
46
|
+
# path - the path (relative to the source) of the page,
|
47
|
+
# post or :draft the default is used in
|
48
|
+
# type - a symbol indicating whether a :page,
|
49
|
+
# a :post or a :draft calls this method
|
45
50
|
#
|
46
51
|
# Returns the default value or nil if none was found
|
47
52
|
def find(path, type, setting)
|
@@ -49,9 +54,9 @@ module Jekyll
|
|
49
54
|
old_scope = nil
|
50
55
|
|
51
56
|
matching_sets(path, type).each do |set|
|
52
|
-
if set[
|
53
|
-
value = set[
|
54
|
-
old_scope = set[
|
57
|
+
if set["values"].key?(setting) && has_precedence?(old_scope, set["scope"])
|
58
|
+
value = set["values"][setting]
|
59
|
+
old_scope = set["scope"]
|
55
60
|
end
|
56
61
|
end
|
57
62
|
value
|
@@ -67,11 +72,11 @@ module Jekyll
|
|
67
72
|
defaults = {}
|
68
73
|
old_scope = nil
|
69
74
|
matching_sets(path, type).each do |set|
|
70
|
-
if has_precedence?(old_scope, set[
|
71
|
-
defaults = Utils.deep_merge_hashes(defaults, set[
|
72
|
-
old_scope = set[
|
75
|
+
if has_precedence?(old_scope, set["scope"])
|
76
|
+
defaults = Utils.deep_merge_hashes(defaults, set["values"])
|
77
|
+
old_scope = set["scope"]
|
73
78
|
else
|
74
|
-
defaults = Utils.deep_merge_hashes(set[
|
79
|
+
defaults = Utils.deep_merge_hashes(set["values"], defaults)
|
75
80
|
end
|
76
81
|
end
|
77
82
|
defaults
|
@@ -91,9 +96,9 @@ module Jekyll
|
|
91
96
|
end
|
92
97
|
|
93
98
|
def applies_path?(scope, path)
|
94
|
-
return true if !scope.key?(
|
99
|
+
return true if !scope.key?("path") || scope["path"].empty?
|
95
100
|
|
96
|
-
scope_path = Pathname.new(scope[
|
101
|
+
scope_path = Pathname.new(scope["path"])
|
97
102
|
Pathname.new(sanitize_path(path)).ascend do |ascended_path|
|
98
103
|
if ascended_path.to_s == scope_path.to_s
|
99
104
|
return true
|
@@ -113,7 +118,7 @@ module Jekyll
|
|
113
118
|
# Returns true if either of the above conditions are satisfied,
|
114
119
|
# otherwise returns false
|
115
120
|
def applies_type?(scope, type)
|
116
|
-
!scope.key?(
|
121
|
+
!scope.key?("type") || scope["type"].eql?(type.to_s)
|
117
122
|
end
|
118
123
|
|
119
124
|
# Checks if a given set of default values is valid
|
@@ -122,7 +127,7 @@ module Jekyll
|
|
122
127
|
#
|
123
128
|
# Returns true if the set is valid and can be used in this class
|
124
129
|
def valid?(set)
|
125
|
-
set.is_a?(Hash) && set[
|
130
|
+
set.is_a?(Hash) && set["values"].is_a?(Hash)
|
126
131
|
end
|
127
132
|
|
128
133
|
# Determines if a new scope has precedence over an old one
|
@@ -131,27 +136,29 @@ module Jekyll
|
|
131
136
|
# new_scope - the new scope hash
|
132
137
|
#
|
133
138
|
# Returns true if the new scope has precedence over the older
|
139
|
+
# rubocop: disable PredicateName
|
134
140
|
def has_precedence?(old_scope, new_scope)
|
135
141
|
return true if old_scope.nil?
|
136
142
|
|
137
|
-
new_path = sanitize_path(new_scope[
|
138
|
-
old_path = sanitize_path(old_scope[
|
143
|
+
new_path = sanitize_path(new_scope["path"])
|
144
|
+
old_path = sanitize_path(old_scope["path"])
|
139
145
|
|
140
146
|
if new_path.length != old_path.length
|
141
147
|
new_path.length >= old_path.length
|
142
|
-
elsif new_scope.key?
|
148
|
+
elsif new_scope.key?("type")
|
143
149
|
true
|
144
150
|
else
|
145
|
-
!old_scope.key?
|
151
|
+
!old_scope.key? "type"
|
146
152
|
end
|
147
153
|
end
|
154
|
+
# rubocop: enable PredicateName
|
148
155
|
|
149
156
|
# Collects a list of sets that match the given path and type
|
150
157
|
#
|
151
158
|
# Returns an array of hashes
|
152
159
|
def matching_sets(path, type)
|
153
160
|
valid_sets.select do |set|
|
154
|
-
!set.key?(
|
161
|
+
!set.key?("scope") || applies?(set["scope"], path, type)
|
155
162
|
end
|
156
163
|
end
|
157
164
|
|
@@ -162,7 +169,7 @@ module Jekyll
|
|
162
169
|
#
|
163
170
|
# Returns an array of hashes
|
164
171
|
def valid_sets
|
165
|
-
sets = @site.config[
|
172
|
+
sets = @site.config["defaults"]
|
166
173
|
return [] unless sets.is_a?(Array)
|
167
174
|
|
168
175
|
sets.map do |set|
|
@@ -170,7 +177,7 @@ module Jekyll
|
|
170
177
|
ensure_time!(update_deprecated_types(set))
|
171
178
|
else
|
172
179
|
Jekyll.logger.warn "Defaults:", "An invalid front-matter default set was found:"
|
173
|
-
Jekyll.logger.warn
|
180
|
+
Jekyll.logger.warn set.to_s
|
174
181
|
nil
|
175
182
|
end
|
176
183
|
end.compact
|
@@ -181,7 +188,7 @@ module Jekyll
|
|
181
188
|
if path.nil? || path.empty?
|
182
189
|
""
|
183
190
|
else
|
184
|
-
path.gsub(
|
191
|
+
path.gsub(%r!\A/!, "").gsub(%r!([^/])\z!, '\1')
|
185
192
|
end
|
186
193
|
end
|
187
194
|
end
|