bridgetown-core 0.21.3 → 1.0.0.alpha3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +35 -0
- data/Rakefile +5 -5
- data/bin/bridgetown +2 -0
- data/bridgetown-core.gemspec +3 -0
- data/lib/bridgetown-core/cache.rb +3 -5
- data/lib/bridgetown-core/cleaner.rb +2 -10
- data/lib/bridgetown-core/collection.rb +62 -86
- data/lib/bridgetown-core/commands/base.rb +62 -2
- data/lib/bridgetown-core/commands/build.rb +33 -12
- data/lib/bridgetown-core/commands/concerns/actions.rb +2 -2
- data/lib/bridgetown-core/commands/concerns/build_options.rb +3 -10
- data/lib/bridgetown-core/commands/concerns/configuration_overridable.rb +3 -1
- data/lib/bridgetown-core/commands/console.rb +3 -3
- data/lib/bridgetown-core/commands/doctor.rb +13 -11
- data/lib/bridgetown-core/commands/new.rb +14 -6
- data/lib/bridgetown-core/commands/plugins.rb +8 -11
- data/lib/bridgetown-core/commands/serve/servlet.rb +4 -4
- data/lib/bridgetown-core/commands/serve.rb +37 -37
- data/lib/bridgetown-core/commands/start.rb +106 -0
- data/lib/bridgetown-core/commands/webpack/webpack.defaults.js.erb +2 -2
- data/lib/bridgetown-core/commands/webpack.rb +1 -1
- data/lib/bridgetown-core/component.rb +2 -6
- data/lib/bridgetown-core/concerns/liquid_renderable.rb +2 -2
- data/lib/bridgetown-core/concerns/site/configurable.rb +1 -13
- data/lib/bridgetown-core/concerns/site/content.rb +17 -118
- data/lib/bridgetown-core/concerns/site/extensible.rb +3 -4
- data/lib/bridgetown-core/concerns/site/localizable.rb +3 -1
- data/lib/bridgetown-core/concerns/site/processable.rb +9 -20
- data/lib/bridgetown-core/concerns/site/renderable.rb +19 -30
- data/lib/bridgetown-core/concerns/site/ssr.rb +53 -0
- data/lib/bridgetown-core/concerns/site/writable.rb +6 -9
- data/lib/bridgetown-core/configuration.rb +19 -48
- data/lib/bridgetown-core/configurations/minitesting.rb +1 -1
- data/lib/bridgetown-core/configurations/turbo.rb +1 -1
- data/lib/bridgetown-core/converter.rb +1 -0
- data/lib/bridgetown-core/converters/erb_templates.rb +8 -5
- data/lib/bridgetown-core/converters/liquid_templates.rb +5 -2
- data/lib/bridgetown-core/converters/markdown/kramdown_parser.rb +1 -1
- data/lib/bridgetown-core/converters/smartypants.rb +1 -0
- data/lib/bridgetown-core/current.rb +4 -0
- data/lib/bridgetown-core/drops/collection_drop.rb +1 -1
- data/lib/bridgetown-core/drops/drop.rb +4 -4
- data/lib/bridgetown-core/drops/generated_page_drop.rb +23 -0
- data/lib/bridgetown-core/drops/resource_drop.rb +3 -3
- data/lib/bridgetown-core/drops/site_drop.rb +3 -47
- data/lib/bridgetown-core/entry_filter.rb +1 -0
- data/lib/bridgetown-core/errors.rb +0 -2
- data/lib/bridgetown-core/filters/url_filters.rb +2 -0
- data/lib/bridgetown-core/filters.rb +11 -12
- data/lib/bridgetown-core/frontmatter_defaults.rb +44 -82
- data/lib/bridgetown-core/{page.rb → generated_page.rb} +34 -60
- data/lib/bridgetown-core/generators/prototype_generator.rb +49 -61
- data/lib/bridgetown-core/helpers.rb +8 -3
- data/lib/bridgetown-core/hooks.rb +2 -2
- data/lib/bridgetown-core/layout.rb +15 -4
- data/lib/bridgetown-core/liquid_renderer.rb +1 -3
- data/lib/bridgetown-core/log_adapter.rb +1 -1
- data/lib/bridgetown-core/log_writer.rb +7 -1
- data/lib/bridgetown-core/model/base.rb +12 -4
- data/lib/bridgetown-core/model/builder_origin.rb +23 -11
- data/lib/bridgetown-core/model/origin.rb +3 -0
- data/lib/bridgetown-core/model/plugin_origin.rb +34 -0
- data/lib/bridgetown-core/model/repo_origin.rb +1 -1
- data/lib/bridgetown-core/plugin_manager.rb +10 -10
- data/lib/bridgetown-core/publisher.rb +1 -1
- data/lib/bridgetown-core/rack/boot.rb +47 -0
- data/lib/bridgetown-core/rack/logger.rb +22 -0
- data/lib/bridgetown-core/rack/roda.rb +66 -0
- data/lib/bridgetown-core/rack/routes.rb +88 -0
- data/lib/bridgetown-core/rack/static_indexes.rb +30 -0
- data/lib/bridgetown-core/reader.rb +20 -47
- data/lib/bridgetown-core/readers/layout_reader.rb +2 -2
- data/lib/bridgetown-core/readers/plugin_content_reader.rb +8 -7
- data/lib/bridgetown-core/renderer.rb +2 -12
- data/lib/bridgetown-core/resource/base.rb +34 -11
- data/lib/bridgetown-core/resource/permalink_processor.rb +23 -12
- data/lib/bridgetown-core/resource/relations.rb +2 -3
- data/lib/bridgetown-core/resource/taxonomy_term.rb +1 -5
- data/lib/bridgetown-core/resource/transformer.rb +8 -6
- data/lib/bridgetown-core/ruby_template_view.rb +6 -8
- data/lib/bridgetown-core/site.rb +4 -8
- data/lib/bridgetown-core/static_file.rb +14 -21
- data/lib/bridgetown-core/tags/find.rb +6 -6
- data/lib/bridgetown-core/tags/highlight.rb +5 -5
- data/lib/bridgetown-core/tags/include.rb +22 -32
- data/lib/bridgetown-core/tags/link.rb +4 -0
- data/lib/bridgetown-core/tags/live_reload_dev_js.rb +13 -0
- data/lib/bridgetown-core/tags/post_url.rb +9 -14
- data/lib/bridgetown-core/tags/render_content.rb +2 -2
- data/lib/bridgetown-core/tasks/bridgetown_tasks.rake +54 -0
- data/lib/bridgetown-core/url.rb +5 -4
- data/lib/bridgetown-core/utils/aux.rb +57 -0
- data/lib/bridgetown-core/utils/ruby_exec.rb +3 -45
- data/lib/bridgetown-core/utils/ruby_front_matter.rb +22 -7
- data/lib/bridgetown-core/utils.rb +60 -33
- data/lib/bridgetown-core/version.rb +2 -2
- data/lib/bridgetown-core/watcher.rb +4 -6
- data/lib/bridgetown-core.rb +16 -23
- data/lib/site_template/Gemfile.erb +6 -2
- data/lib/site_template/README.md +6 -6
- data/lib/site_template/Rakefile +49 -0
- data/lib/site_template/bridgetown.config.yml +2 -3
- data/lib/site_template/config/puma.rb +27 -0
- data/lib/site_template/config.ru +7 -0
- data/lib/site_template/frontend/javascript/index.js.erb +3 -3
- data/lib/site_template/package.json.erb +7 -12
- data/lib/site_template/server/roda_app.rb +22 -0
- data/lib/site_template/server/routes/hello.rb.sample +10 -0
- data/lib/site_template/src/_components/head.liquid +2 -1
- data/lib/site_template/src/about.md +0 -1
- data/lib/site_template/src/posts.md +2 -3
- metadata +63 -18
- data/lib/bridgetown-core/concerns/data_accessible.rb +0 -20
- data/lib/bridgetown-core/concerns/validatable.rb +0 -56
- data/lib/bridgetown-core/document.rb +0 -437
- data/lib/bridgetown-core/drops/document_drop.rb +0 -80
- data/lib/bridgetown-core/drops/excerpt_drop.rb +0 -19
- data/lib/bridgetown-core/drops/page_drop.rb +0 -18
- data/lib/bridgetown-core/excerpt.rb +0 -200
- data/lib/bridgetown-core/readers/data_reader.rb +0 -89
- data/lib/bridgetown-core/readers/page_reader.rb +0 -26
- data/lib/bridgetown-core/readers/post_reader.rb +0 -109
- data/lib/bridgetown-core/regenerator.rb +0 -202
- data/lib/bridgetown-core/related_posts.rb +0 -55
- data/lib/site_template/config/.keep +0 -0
- data/lib/site_template/start.js +0 -17
- data/lib/site_template/sync.js +0 -35
@@ -18,7 +18,8 @@ module Bridgetown
|
|
18
18
|
# Logic to do the Liquid content conversion.
|
19
19
|
#
|
20
20
|
# @param content [String] Content of the file (without front matter).
|
21
|
-
# @param convertible [
|
21
|
+
# @param convertible [
|
22
|
+
# Bridgetown::GeneratedPage, Bridgetown::Resource::Base, Bridgetown::Layout]
|
22
23
|
# The instantiated object which is processing the file.
|
23
24
|
#
|
24
25
|
# @return [String] The converted content.
|
@@ -55,6 +56,8 @@ module Bridgetown
|
|
55
56
|
# rubocop: enable Metrics/MethodLength
|
56
57
|
# rubocop: enable Metrics/AbcSize
|
57
58
|
|
59
|
+
# @param ext [String]
|
60
|
+
# @param convertible [Bridgetown::Resource::Base, Bridgetown::GeneratedPage]
|
58
61
|
def matches(ext, convertible)
|
59
62
|
if convertible.render_with_liquid?
|
60
63
|
convertible.data[:template_engine] = "liquid"
|
@@ -84,7 +87,7 @@ module Bridgetown
|
|
84
87
|
def configure_payload(content = nil)
|
85
88
|
payload["page"] = document.to_liquid
|
86
89
|
payload["paginator"] = document.respond_to?(:paginator) ? document.paginator.to_liquid : nil
|
87
|
-
payload["layout"] = @layout ? @layout.data : {}
|
90
|
+
payload["layout"] = @layout ? @layout.to_liquid.merge({ data: @layout.data }) : {}
|
88
91
|
payload["content"] = content
|
89
92
|
end
|
90
93
|
|
@@ -8,7 +8,7 @@ module Bridgetown
|
|
8
8
|
mutable false
|
9
9
|
|
10
10
|
def_delegator :@obj, :write?, :output
|
11
|
-
def_delegators :@obj, :label, :
|
11
|
+
def_delegators :@obj, :label, :files, :relative_path, :resources, :static_files
|
12
12
|
|
13
13
|
private def_delegator :@obj, :metadata, :fallback_data
|
14
14
|
|
@@ -28,7 +28,7 @@ module Bridgetown
|
|
28
28
|
# drop.
|
29
29
|
#
|
30
30
|
# Returns nothing
|
31
|
-
def initialize(obj)
|
31
|
+
def initialize(obj) # rubocop:disable Lint/MissingSuper
|
32
32
|
@obj = obj
|
33
33
|
end
|
34
34
|
|
@@ -69,11 +69,11 @@ module Bridgetown
|
|
69
69
|
if respond_to?(setter)
|
70
70
|
public_send(setter, val)
|
71
71
|
elsif respond_to?(key.to_s)
|
72
|
-
|
73
|
-
mutations[key] = val
|
74
|
-
else
|
72
|
+
unless self.class.mutable?
|
75
73
|
raise Errors::DropMutationException, "Key #{key} cannot be set in the drop."
|
76
74
|
end
|
75
|
+
|
76
|
+
mutations[key] = val
|
77
77
|
else
|
78
78
|
fallback_data[key] = val
|
79
79
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Bridgetown
|
4
|
+
module Drops
|
5
|
+
class GeneratedPageDrop < Drop
|
6
|
+
extend Forwardable
|
7
|
+
|
8
|
+
mutable false
|
9
|
+
|
10
|
+
def_delegators :@obj,
|
11
|
+
:data,
|
12
|
+
:content,
|
13
|
+
:dir,
|
14
|
+
:name,
|
15
|
+
:path,
|
16
|
+
:url,
|
17
|
+
:relative_url,
|
18
|
+
:relative_path
|
19
|
+
|
20
|
+
private def_delegator :@obj, :data, :fallback_data
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -11,7 +11,6 @@ module Bridgetown
|
|
11
11
|
|
12
12
|
mutable false
|
13
13
|
|
14
|
-
def_delegator :@obj, :relative_path, :path
|
15
14
|
def_delegators :@obj,
|
16
15
|
:id,
|
17
16
|
:data,
|
@@ -20,6 +19,7 @@ module Bridgetown
|
|
20
19
|
:summary,
|
21
20
|
:to_s,
|
22
21
|
:absolute_url,
|
22
|
+
:path,
|
23
23
|
:relative_path,
|
24
24
|
:relative_url,
|
25
25
|
:date,
|
@@ -32,8 +32,8 @@ module Bridgetown
|
|
32
32
|
@collection ||= @obj.collection.to_liquid
|
33
33
|
end
|
34
34
|
|
35
|
-
def
|
36
|
-
|
35
|
+
def relative_path
|
36
|
+
@relative_path ||= @obj.relative_path.to_s
|
37
37
|
end
|
38
38
|
|
39
39
|
def <=>(other)
|
@@ -13,7 +13,6 @@ module Bridgetown
|
|
13
13
|
:data,
|
14
14
|
:locale,
|
15
15
|
:time,
|
16
|
-
:pages,
|
17
16
|
:generated_pages,
|
18
17
|
:static_files,
|
19
18
|
:tags,
|
@@ -25,51 +24,10 @@ module Bridgetown
|
|
25
24
|
|
26
25
|
attr_writer :current_document
|
27
26
|
|
28
|
-
def [](key)
|
29
|
-
if !@obj.uses_resource? && !%w(posts data).freeze.include?(key) &&
|
30
|
-
@obj.collections.key?(key)
|
31
|
-
return @obj.collections[key].docs
|
32
|
-
end
|
33
|
-
|
34
|
-
super(key)
|
35
|
-
end
|
36
|
-
|
37
|
-
def key?(key)
|
38
|
-
(!@obj.uses_resource? && key != "posts" && @obj.collections.key?(key)) || super
|
39
|
-
end
|
40
|
-
|
41
27
|
def uses_resource
|
42
28
|
@obj.uses_resource?
|
43
29
|
end
|
44
30
|
|
45
|
-
def posts
|
46
|
-
unless @obj.uses_resource?
|
47
|
-
@site_posts ||= @obj.collections.posts.docs.sort { |a, b| b <=> a }
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
# TODO: deprecate before v1.0
|
52
|
-
def html_pages
|
53
|
-
@site_html_pages ||= @obj.pages.select do |page|
|
54
|
-
page.html? || page.url.end_with?("/")
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
# TODO: deprecate before v1.0
|
59
|
-
def collections
|
60
|
-
@site_collections ||= @obj.collections.values.sort_by(&:label).map(&:to_liquid)
|
61
|
-
end
|
62
|
-
|
63
|
-
# `Site#documents` cannot be memoized so that `Site#docs_to_write` can access the
|
64
|
-
# latest state of the attribute.
|
65
|
-
#
|
66
|
-
# Since this method will be called after `Site#pre_render` hook, the `Site#documents`
|
67
|
-
# array shouldn't thereafter change and can therefore be safely memoized to prevent
|
68
|
-
# additional computation of `Site#documents`.
|
69
|
-
def documents
|
70
|
-
@documents ||= @obj.documents
|
71
|
-
end
|
72
|
-
|
73
31
|
def resources
|
74
32
|
@resources ||= @obj.resources
|
75
33
|
end
|
@@ -82,11 +40,9 @@ module Bridgetown
|
|
82
40
|
@site_metadata ||= @obj.data["site_metadata"]
|
83
41
|
end
|
84
42
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
# return nil for `{{ site.config }}` even if --config was passed via CLI
|
89
|
-
def config; end
|
43
|
+
def config
|
44
|
+
@obj.config
|
45
|
+
end
|
90
46
|
end
|
91
47
|
end
|
92
48
|
end
|
@@ -51,6 +51,7 @@ module Bridgetown
|
|
51
51
|
|
52
52
|
def compute_absolute_url(input)
|
53
53
|
return if input.nil?
|
54
|
+
return input.absolute_url if input.respond_to?(:absolute_url)
|
54
55
|
|
55
56
|
input = input.url if input.respond_to?(:url)
|
56
57
|
return input if Addressable::URI.parse(input.to_s).absolute?
|
@@ -66,6 +67,7 @@ module Bridgetown
|
|
66
67
|
|
67
68
|
def compute_relative_url(input)
|
68
69
|
return if input.nil?
|
70
|
+
return input.relative_url if input.respond_to?(:relative_url)
|
69
71
|
|
70
72
|
input = input.url if input.respond_to?(:url)
|
71
73
|
return input if Addressable::URI.parse(input.to_s).absolute?
|
@@ -104,7 +104,7 @@ module Bridgetown
|
|
104
104
|
def obfuscate_link(input, prefix = "mailto")
|
105
105
|
link = "<a href=\"#{prefix}:#{input}\">#{input}</a>"
|
106
106
|
script = "<script type=\"text/javascript\">document.currentScript.insertAdjacentHTML('"
|
107
|
-
script += "beforebegin', '#{rot47(link).gsub(%r!\\!, '\\\\\\')}'.replace(/[!-~]/g,"
|
107
|
+
script += "beforebegin', '#{rot47(link).gsub(%r!\\!, '\\\\\\')}'.replace(/[!-~]/g," # rubocop:disable Style/StringLiteralsInInterpolation
|
108
108
|
script += "function(c){{var j=c.charCodeAt(0);if((j>=33)&&(j<=126)){"
|
109
109
|
script += "return String.fromCharCode(33+((j+ 14)%94));}"
|
110
110
|
script += "else{return String.fromCharCode(j);}}}));</script>"
|
@@ -180,7 +180,7 @@ module Bridgetown
|
|
180
180
|
# their `#inspect` string object.
|
181
181
|
#
|
182
182
|
# Returns the filtered array of objects
|
183
|
-
def where(input, property, value)
|
183
|
+
def where(input, property, value) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
184
184
|
return input if !property || value.is_a?(Array) || value.is_a?(Hash)
|
185
185
|
return input unless input.respond_to?(:select)
|
186
186
|
|
@@ -194,11 +194,9 @@ module Bridgetown
|
|
194
194
|
@where_filter_cache[input_id][property] ||= {}
|
195
195
|
|
196
196
|
# stash or retrive results to return
|
197
|
-
@where_filter_cache[input_id][property][value] ||=
|
198
|
-
|
199
|
-
|
200
|
-
end.to_a
|
201
|
-
end
|
197
|
+
@where_filter_cache[input_id][property][value] ||= input.select do |object|
|
198
|
+
compare_property_vs_target(item_property(object, property), value)
|
199
|
+
end.to_a
|
202
200
|
end
|
203
201
|
|
204
202
|
# Filters an array of objects against an expression
|
@@ -247,13 +245,14 @@ module Bridgetown
|
|
247
245
|
if property.nil?
|
248
246
|
input.sort
|
249
247
|
else
|
250
|
-
|
248
|
+
case nils
|
249
|
+
when "first"
|
251
250
|
order = - 1
|
252
|
-
|
251
|
+
when "last"
|
253
252
|
order = + 1
|
254
253
|
else
|
255
254
|
raise ArgumentError, "Invalid nils order: " \
|
256
|
-
|
255
|
+
"'#{nils}' is not a valid nils order. It must be 'first' or 'last'."
|
257
256
|
end
|
258
257
|
|
259
258
|
sort_input(input, property, order)
|
@@ -327,7 +326,7 @@ module Bridgetown
|
|
327
326
|
# If the property doesn't exist, return the sort order respective of
|
328
327
|
# which item doesn't have the property.
|
329
328
|
# We also utilize the Schwartzian transform to make this more efficient.
|
330
|
-
def sort_input(input, property, order)
|
329
|
+
def sort_input(input, property, order) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
331
330
|
input.map { |item| [item_property(item, property), item] }
|
332
331
|
.sort! do |a_info, b_info|
|
333
332
|
a_property = a_info.first
|
@@ -413,7 +412,7 @@ module Bridgetown
|
|
413
412
|
case item
|
414
413
|
when Hash
|
415
414
|
pairs = item.map { |k, v| as_liquid([k, v]) }
|
416
|
-
Hash[pairs]
|
415
|
+
Hash[pairs] # rubocop:todo Style/HashConversion
|
417
416
|
when Array
|
418
417
|
item.map { |i| as_liquid(i) }
|
419
418
|
else
|
@@ -1,9 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Bridgetown
|
4
|
-
# This class handles custom defaults for
|
4
|
+
# This class handles custom defaults for front matter settings.
|
5
5
|
# It is exposed via the frontmatter_defaults method on the site class.
|
6
|
-
# TODO: needs simplification/refactoring.
|
7
6
|
class FrontmatterDefaults
|
8
7
|
# @return [Bridgetown::Site]
|
9
8
|
attr_reader :site
|
@@ -16,24 +15,6 @@ module Bridgetown
|
|
16
15
|
@glob_cache = {}
|
17
16
|
end
|
18
17
|
|
19
|
-
def update_deprecated_types(set)
|
20
|
-
return set unless set.key?("scope") && set["scope"].key?("type")
|
21
|
-
|
22
|
-
set["scope"]["type"] =
|
23
|
-
case set["scope"]["type"]
|
24
|
-
when "page"
|
25
|
-
Deprecator.defaults_deprecate_type("page", "pages")
|
26
|
-
"pages"
|
27
|
-
when "post"
|
28
|
-
Deprecator.defaults_deprecate_type("post", "posts")
|
29
|
-
"posts"
|
30
|
-
else
|
31
|
-
set["scope"]["type"]
|
32
|
-
end
|
33
|
-
|
34
|
-
set
|
35
|
-
end
|
36
|
-
|
37
18
|
def ensure_time!(set)
|
38
19
|
return set unless set.key?("values") && set["values"].key?("date")
|
39
20
|
return set if set["values"]["date"].is_a?(Time)
|
@@ -45,44 +26,19 @@ module Bridgetown
|
|
45
26
|
set
|
46
27
|
end
|
47
28
|
|
48
|
-
#
|
49
|
-
#
|
50
|
-
# path - the path (relative to the source) of the page or
|
51
|
-
# post the default is used in
|
52
|
-
# type - a symbol indicating whether a :page,
|
53
|
-
# a :post calls this method
|
54
|
-
#
|
55
|
-
# Returns the default value or nil if none was found
|
56
|
-
def find(path, type, setting)
|
57
|
-
merged_data = {}
|
58
|
-
merge_data_cascade_for_path(path, merged_data)
|
59
|
-
return merged_data[setting] if merged_data.key?(setting)
|
60
|
-
|
61
|
-
value = nil
|
62
|
-
old_scope = nil
|
63
|
-
|
64
|
-
matching_sets(path, type).each do |set|
|
65
|
-
if set["values"].key?(setting) && has_precedence?(old_scope, set["scope"])
|
66
|
-
value = set["values"][setting]
|
67
|
-
old_scope = set["scope"]
|
68
|
-
end
|
69
|
-
end
|
70
|
-
value
|
71
|
-
end
|
72
|
-
|
73
|
-
# Collects a hash with all default values for a page or post
|
29
|
+
# Collects a hash with all default values for a resource
|
74
30
|
#
|
75
|
-
# path
|
76
|
-
#
|
31
|
+
# @param path [String] the relative path of the resource
|
32
|
+
# @param collection [Symbol] :posts, :pages, etc.
|
77
33
|
#
|
78
|
-
#
|
79
|
-
def all(path,
|
34
|
+
# @returns [Hash] all default values (an empty hash if there are none)
|
35
|
+
def all(path, collection)
|
80
36
|
defaults = {}
|
81
37
|
|
82
38
|
merge_data_cascade_for_path(path, defaults)
|
83
39
|
|
84
40
|
old_scope = nil
|
85
|
-
matching_sets(path,
|
41
|
+
matching_sets(path, collection).each do |set|
|
86
42
|
if has_precedence?(old_scope, set["scope"])
|
87
43
|
defaults = Utils.deep_merge_hashes(defaults, set["values"])
|
88
44
|
old_scope = set["scope"]
|
@@ -105,22 +61,22 @@ module Bridgetown
|
|
105
61
|
end
|
106
62
|
end
|
107
63
|
|
108
|
-
# Checks if a given default setting scope matches the given path and
|
64
|
+
# Checks if a given default setting scope matches the given path and collection
|
109
65
|
#
|
110
66
|
# scope - the hash indicating the scope, as defined in bridgetown.config.yml
|
111
67
|
# path - the path to check for
|
112
|
-
#
|
68
|
+
# collection - the collection (:posts or :pages) to check for
|
113
69
|
#
|
114
|
-
# Returns true if the scope applies to the given
|
115
|
-
def applies?(scope, path,
|
116
|
-
|
70
|
+
# Returns true if the scope applies to the given collection and path
|
71
|
+
def applies?(scope, path, collection)
|
72
|
+
applies_collection?(scope, collection) && applies_path?(scope, path)
|
117
73
|
end
|
118
74
|
|
119
75
|
def applies_path?(scope, path)
|
120
76
|
rel_scope_path = scope["path"]
|
121
77
|
return true if !rel_scope_path.is_a?(String) || rel_scope_path.empty?
|
122
78
|
|
123
|
-
sanitized_path = sanitize_path(path)
|
79
|
+
sanitized_path = strip_collections_dir(sanitize_path(path))
|
124
80
|
|
125
81
|
if rel_scope_path.include?("*")
|
126
82
|
glob_scope(sanitized_path, rel_scope_path)
|
@@ -159,26 +115,24 @@ module Bridgetown
|
|
159
115
|
path.sub(slashed_coll_dir, "")
|
160
116
|
end
|
161
117
|
|
162
|
-
# Determines whether the scope applies to
|
163
|
-
# The scope applies to the
|
164
|
-
# 1. no '
|
165
|
-
# 2. the '
|
118
|
+
# Determines whether the scope applies to collection.
|
119
|
+
# The scope applies to the collection if:
|
120
|
+
# 1. no 'collection' is specified
|
121
|
+
# 2. the 'collection' in the scope is the same as the collection asked about
|
166
122
|
#
|
167
|
-
# scope
|
168
|
-
#
|
169
|
-
# its defaults.
|
123
|
+
# @param scope [Hash] the defaults set being asked about
|
124
|
+
# @param collection [Symbol] the collection of the resource being processed
|
170
125
|
#
|
171
|
-
#
|
172
|
-
|
173
|
-
|
174
|
-
!scope.key?("type") || scope["type"].eql?(type.to_s)
|
126
|
+
# @returns [Boolean] whether either of the above conditions are satisfied
|
127
|
+
def applies_collection?(scope, collection)
|
128
|
+
!scope.key?("collection") || scope["collection"].eql?(collection.to_s)
|
175
129
|
end
|
176
130
|
|
177
131
|
# Checks if a given set of default values is valid
|
178
132
|
#
|
179
|
-
# set
|
133
|
+
# @param set [Hash] the default value hash as defined in bridgetown.config.yml
|
180
134
|
#
|
181
|
-
#
|
135
|
+
# @returns [Boolean] if the set is valid and can be used
|
182
136
|
def valid?(set)
|
183
137
|
set.is_a?(Hash) && set["values"].is_a?(Hash)
|
184
138
|
end
|
@@ -198,24 +152,22 @@ module Bridgetown
|
|
198
152
|
|
199
153
|
if new_path.length != old_path.length
|
200
154
|
new_path.length >= old_path.length
|
201
|
-
elsif new_scope.key?("
|
155
|
+
elsif new_scope.key?("collection")
|
202
156
|
true
|
203
157
|
else
|
204
|
-
!old_scope.key? "
|
158
|
+
!old_scope.key? "collection"
|
205
159
|
end
|
206
160
|
end
|
207
161
|
# rubocop: enable Naming/PredicateName
|
208
162
|
|
209
|
-
# Collects a list of sets that match the given path and
|
163
|
+
# Collects a list of sets that match the given path and collection
|
210
164
|
#
|
211
|
-
#
|
212
|
-
def matching_sets(path,
|
165
|
+
# @return [Array<Hash>]
|
166
|
+
def matching_sets(path, collection)
|
213
167
|
@matched_set_cache ||= {}
|
214
168
|
@matched_set_cache[path] ||= {}
|
215
|
-
@matched_set_cache[path][
|
216
|
-
|
217
|
-
!set.key?("scope") || applies?(set["scope"], path, type)
|
218
|
-
end
|
169
|
+
@matched_set_cache[path][collection] ||= valid_sets.select do |set|
|
170
|
+
!set.key?("scope") || applies?(set["scope"], path, collection)
|
219
171
|
end
|
220
172
|
end
|
221
173
|
|
@@ -224,14 +176,16 @@ module Bridgetown
|
|
224
176
|
# This is not cached to allow plugins to modify the configuration
|
225
177
|
# and have their changes take effect
|
226
178
|
#
|
227
|
-
#
|
179
|
+
# @return [Array<Hash>]
|
228
180
|
def valid_sets
|
229
181
|
sets = site.config["defaults"]
|
230
182
|
return [] unless sets.is_a?(Array)
|
231
183
|
|
232
184
|
sets.map do |set|
|
233
185
|
if valid?(set)
|
234
|
-
|
186
|
+
massage_scope!(set)
|
187
|
+
# TODO: is this trip really necessary?
|
188
|
+
ensure_time!(set)
|
235
189
|
else
|
236
190
|
Bridgetown.logger.warn "Defaults:", "An invalid front-matter default set was found:"
|
237
191
|
Bridgetown.logger.warn set.to_s
|
@@ -240,10 +194,18 @@ module Bridgetown
|
|
240
194
|
end.compact
|
241
195
|
end
|
242
196
|
|
243
|
-
#
|
197
|
+
# Set path to blank if not specified and alias older type to collection
|
198
|
+
def massage_scope!(set)
|
199
|
+
set["scope"] ||= {}
|
200
|
+
set["scope"]["path"] ||= ""
|
201
|
+
return unless set["scope"]["type"] && !set["scope"]["collection"]
|
202
|
+
|
203
|
+
set["scope"]["collection"] = set["scope"]["type"]
|
204
|
+
end
|
244
205
|
|
245
206
|
SANITIZATION_REGEX = %r!\A/|(?<=[^/])\z!.freeze
|
246
207
|
|
208
|
+
# Sanitizes the given path by removing a leading and adding a trailing slash
|
247
209
|
def sanitize_path(path)
|
248
210
|
if path.nil? || path.empty?
|
249
211
|
""
|