bridgetown-core 0.21.1 → 1.0.0.alpha1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/bridgetown +2 -0
- data/bridgetown-core.gemspec +3 -0
- data/lib/bridgetown-core/cleaner.rb +0 -8
- data/lib/bridgetown-core/collection.rb +59 -81
- data/lib/bridgetown-core/commands/base.rb +60 -1
- data/lib/bridgetown-core/commands/build.rb +26 -6
- 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/doctor.rb +3 -3
- data/lib/bridgetown-core/commands/new.rb +9 -3
- data/lib/bridgetown-core/commands/plugins.rb +1 -2
- data/lib/bridgetown-core/commands/serve.rb +14 -12
- 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/concerns/site/configurable.rb +0 -12
- data/lib/bridgetown-core/concerns/site/content.rb +16 -117
- 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 +5 -8
- data/lib/bridgetown-core/configuration.rb +18 -47
- data/lib/bridgetown-core/configurations/minitesting.rb +1 -1
- data/lib/bridgetown-core/configurations/turbo.rb +1 -1
- data/lib/bridgetown-core/converters/erb_templates.rb +2 -1
- data/lib/bridgetown-core/converters/liquid_templates.rb +3 -2
- data/lib/bridgetown-core/current.rb +4 -0
- data/lib/bridgetown-core/drops/collection_drop.rb +1 -1
- 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/errors.rb +0 -2
- data/lib/bridgetown-core/filters/url_filters.rb +3 -1
- data/lib/bridgetown-core/frontmatter_defaults.rb +52 -88
- data/lib/bridgetown-core/{page.rb → generated_page.rb} +34 -58
- data/lib/bridgetown-core/generators/prototype_generator.rb +13 -24
- data/lib/bridgetown-core/helpers.rb +7 -2
- data/lib/bridgetown-core/layout.rb +15 -4
- data/lib/bridgetown-core/log_writer.rb +6 -0
- data/lib/bridgetown-core/model/base.rb +10 -2
- data/lib/bridgetown-core/model/builder_origin.rb +22 -10
- 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 +8 -8
- 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 +92 -0
- data/lib/bridgetown-core/rack/static_indexes.rb +30 -0
- data/lib/bridgetown-core/reader.rb +20 -47
- data/lib/bridgetown-core/readers/plugin_content_reader.rb +8 -7
- data/lib/bridgetown-core/renderer.rb +1 -11
- data/lib/bridgetown-core/resource/base.rb +50 -26
- data/lib/bridgetown-core/resource/permalink_processor.rb +20 -10
- data/lib/bridgetown-core/resource/relations.rb +2 -3
- data/lib/bridgetown-core/resource/transformer.rb +1 -1
- data/lib/bridgetown-core/ruby_template_view.rb +5 -5
- data/lib/bridgetown-core/site.rb +4 -8
- data/lib/bridgetown-core/static_file.rb +10 -15
- data/lib/bridgetown-core/tags/include.rb +0 -13
- 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 +4 -9
- data/lib/bridgetown-core/tasks/bridgetown_tasks.rake +54 -0
- data/lib/bridgetown-core/url.rb +2 -1
- 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 +53 -24
- data/lib/bridgetown-core/version.rb +2 -2
- data/lib/bridgetown-core/watcher.rb +2 -4
- data/lib/bridgetown-core.rb +14 -22
- 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 +8 -13
- 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 +62 -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
@@ -34,32 +34,28 @@ module Bridgetown
|
|
34
34
|
"encoding" => "utf-8",
|
35
35
|
"markdown_ext" => "markdown,mkdown,mkdn,mkd,md",
|
36
36
|
"strict_front_matter" => false,
|
37
|
-
"slugify_categories" => true,
|
38
37
|
"slugify_mode" => "pretty",
|
39
38
|
|
40
39
|
# Filtering Content
|
41
|
-
"limit_posts" => 0,
|
42
40
|
"future" => false,
|
43
41
|
"unpublished" => false,
|
44
42
|
"ruby_in_front_matter" => true,
|
45
43
|
|
46
44
|
# Conversion
|
45
|
+
"content_engine" => "resource",
|
47
46
|
"markdown" => "kramdown",
|
48
47
|
"highlighter" => "rouge",
|
49
|
-
"lsi" => false,
|
50
48
|
"excerpt_separator" => "\n\n",
|
51
|
-
"incremental" => false,
|
52
49
|
|
53
50
|
# Serving
|
54
|
-
"detach" => false, # default to not detaching the server
|
55
51
|
"port" => "4000",
|
56
52
|
"host" => "127.0.0.1",
|
57
53
|
"base_path" => "/",
|
58
54
|
"show_dir_listing" => false,
|
59
55
|
|
60
56
|
# Output Configuration
|
61
|
-
"available_locales" => [
|
62
|
-
"default_locale" =>
|
57
|
+
"available_locales" => [:en],
|
58
|
+
"default_locale" => :en,
|
63
59
|
"permalink" => nil, # default is set according to content engine
|
64
60
|
"timezone" => nil, # use the local timezone
|
65
61
|
|
@@ -103,6 +99,7 @@ module Bridgetown
|
|
103
99
|
def from(user_config, starting_defaults = DEFAULTS)
|
104
100
|
Utils.deep_merge_hashes(starting_defaults.deep_dup, Configuration[user_config])
|
105
101
|
.merge_environment_specific_options!
|
102
|
+
.setup_locales
|
106
103
|
.add_default_collections
|
107
104
|
.add_default_excludes
|
108
105
|
.check_include_exclude
|
@@ -247,6 +244,12 @@ module Bridgetown
|
|
247
244
|
self
|
248
245
|
end
|
249
246
|
|
247
|
+
def setup_locales
|
248
|
+
self.default_locale = default_locale.to_sym
|
249
|
+
available_locales.map!(&:to_sym)
|
250
|
+
self
|
251
|
+
end
|
252
|
+
|
250
253
|
def add_default_collections # rubocop:todo all
|
251
254
|
# It defaults to `{}`, so this is only if someone sets it to null manually.
|
252
255
|
return self if self[:collections].nil?
|
@@ -263,23 +266,16 @@ module Bridgetown
|
|
263
266
|
self[:collections][:posts][:output] = true
|
264
267
|
self[:collections][:posts][:sort_direction] ||= "descending"
|
265
268
|
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
self[:collections][:pages][:permalink] ||= "/:path/"
|
269
|
+
self[:permalink] = "pretty" if self[:permalink].blank?
|
270
|
+
self[:collections][:pages] = {} unless self[:collections][:pages]
|
271
|
+
self[:collections][:pages][:output] = true
|
272
|
+
self[:collections][:pages][:permalink] ||= "/:locale/:path/"
|
271
273
|
|
272
|
-
|
273
|
-
|
274
|
+
self[:collections][:data] = {} unless self[:collections][:data]
|
275
|
+
self[:collections][:data][:output] = false
|
274
276
|
|
275
|
-
|
276
|
-
|
277
|
-
end
|
278
|
-
else
|
279
|
-
self[:permalink] = "date" if self[:permalink].blank?
|
280
|
-
unless self[:collections][:posts][:permalink]
|
281
|
-
self[:collections][:posts][:permalink] = style_to_permalink(self[:permalink])
|
282
|
-
end
|
277
|
+
unless self[:collections][:posts][:permalink]
|
278
|
+
self[:collections][:posts][:permalink] = self[:permalink]
|
283
279
|
end
|
284
280
|
|
285
281
|
self
|
@@ -304,26 +300,6 @@ module Bridgetown
|
|
304
300
|
self["ruby_in_front_matter"]
|
305
301
|
end
|
306
302
|
|
307
|
-
# Deprecated, to be removed when Bridgetown goes Resource-only
|
308
|
-
def style_to_permalink(permalink_style) # rubocop:todo Metrics/CyclomaticComplexity
|
309
|
-
case permalink_style.to_s.to_sym
|
310
|
-
when :pretty
|
311
|
-
"/:categories/:year/:month/:day/:title/"
|
312
|
-
when :simple
|
313
|
-
"/:categories/:title/"
|
314
|
-
when :none
|
315
|
-
"/:categories/:title:output_ext"
|
316
|
-
when :date
|
317
|
-
"/:categories/:year/:month/:day/:title:output_ext"
|
318
|
-
when :ordinal
|
319
|
-
"/:categories/:year/:y_day/:title:output_ext"
|
320
|
-
when :weekdate
|
321
|
-
"/:categories/:year/W:week/:short_day/:title:output_ext"
|
322
|
-
else
|
323
|
-
permalink_style.to_s
|
324
|
-
end
|
325
|
-
end
|
326
|
-
|
327
303
|
def check_include_exclude
|
328
304
|
%w(include exclude).each do |option|
|
329
305
|
next unless key?(option)
|
@@ -333,11 +309,6 @@ module Bridgetown
|
|
333
309
|
"'#{option}' should be set as an array, but was: #{self[option].inspect}."
|
334
310
|
end
|
335
311
|
|
336
|
-
unless self[:include].include?("_pages") || self[:content_engine] == "resource"
|
337
|
-
# add _pages to includes set
|
338
|
-
self[:include] << "_pages"
|
339
|
-
end
|
340
|
-
|
341
312
|
self
|
342
313
|
end
|
343
314
|
|
@@ -65,7 +65,7 @@ create_file "test/test_homepage.rb" do
|
|
65
65
|
class TestHomepage < Minitest::Test
|
66
66
|
context "homepage" do
|
67
67
|
setup do
|
68
|
-
page = site.pages.find { |doc| doc.
|
68
|
+
page = site.collections.pages.resources.find { |doc| doc.relative_url == "/" }
|
69
69
|
document_root page
|
70
70
|
end
|
71
71
|
should "exist" do
|
@@ -104,7 +104,8 @@ module Bridgetown
|
|
104
104
|
# Logic to do the ERB content conversion.
|
105
105
|
#
|
106
106
|
# @param content [String] Content of the file (without front matter).
|
107
|
-
# @param convertible [
|
107
|
+
# @param convertible [
|
108
|
+
# Bridgetown::GeneratedPage, Bridgetown::Resource::Base, Bridgetown::Layout]
|
108
109
|
# The instantiated object which is processing the file.
|
109
110
|
#
|
110
111
|
# @return [String] The converted content.
|
@@ -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.
|
@@ -84,7 +85,7 @@ module Bridgetown
|
|
84
85
|
def configure_payload(content = nil)
|
85
86
|
payload["page"] = document.to_liquid
|
86
87
|
payload["paginator"] = document.respond_to?(:paginator) ? document.paginator.to_liquid : nil
|
87
|
-
payload["layout"] = @layout ? @layout.data : {}
|
88
|
+
payload["layout"] = @layout ? @layout.to_liquid.merge({ data: @layout.data }) : {}
|
88
89
|
payload["content"] = content
|
89
90
|
end
|
90
91
|
|
@@ -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
|
|
@@ -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
|
@@ -49,8 +49,9 @@ module Bridgetown
|
|
49
49
|
|
50
50
|
private
|
51
51
|
|
52
|
-
def compute_absolute_url(input)
|
52
|
+
def compute_absolute_url(input) # rubocop:todo Metrics/CyclomaticComplexity
|
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?
|
@@ -1,13 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Bridgetown
|
4
|
-
# This class handles custom defaults for
|
5
|
-
# These are set in bridgetown.config.yml and apply both to internal use (e.g. layout)
|
6
|
-
# and the data available to liquid.
|
7
|
-
#
|
4
|
+
# This class handles custom defaults for front matter settings.
|
8
5
|
# It is exposed via the frontmatter_defaults method on the site class.
|
9
6
|
class FrontmatterDefaults
|
10
|
-
#
|
7
|
+
# @return [Bridgetown::Site]
|
8
|
+
attr_reader :site
|
9
|
+
|
11
10
|
def initialize(site)
|
12
11
|
@site = site
|
13
12
|
end
|
@@ -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"]
|
@@ -96,8 +52,8 @@ module Bridgetown
|
|
96
52
|
private
|
97
53
|
|
98
54
|
def merge_data_cascade_for_path(path, merged_data)
|
99
|
-
absolute_path =
|
100
|
-
|
55
|
+
absolute_path = site.in_source_dir(path)
|
56
|
+
site.defaults_reader.path_defaults
|
101
57
|
.select { |k, _v| absolute_path.include? k }
|
102
58
|
.sort_by { |k, _v| k.length }
|
103
59
|
.each do |defaults|
|
@@ -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)
|
@@ -130,7 +86,7 @@ module Bridgetown
|
|
130
86
|
end
|
131
87
|
|
132
88
|
def glob_scope(sanitized_path, rel_scope_path)
|
133
|
-
site_source = Pathname.new(
|
89
|
+
site_source = Pathname.new(site.source)
|
134
90
|
abs_scope_path = site_source.join(rel_scope_path).to_s
|
135
91
|
|
136
92
|
glob_cache(abs_scope_path).each do |scope_path|
|
@@ -152,33 +108,31 @@ module Bridgetown
|
|
152
108
|
end
|
153
109
|
|
154
110
|
def strip_collections_dir(path)
|
155
|
-
collections_dir =
|
111
|
+
collections_dir = site.config["collections_dir"]
|
156
112
|
slashed_coll_dir = collections_dir.empty? ? "/" : "#{collections_dir}/"
|
157
113
|
return path if collections_dir.empty? || !path.to_s.start_with?(slashed_coll_dir)
|
158
114
|
|
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,23 +152,23 @@ 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][
|
169
|
+
@matched_set_cache[path][collection] ||= begin
|
216
170
|
valid_sets.select do |set|
|
217
|
-
!set.key?("scope") || applies?(set["scope"], path,
|
171
|
+
!set.key?("scope") || applies?(set["scope"], path, collection)
|
218
172
|
end
|
219
173
|
end
|
220
174
|
end
|
@@ -224,14 +178,16 @@ module Bridgetown
|
|
224
178
|
# This is not cached to allow plugins to modify the configuration
|
225
179
|
# and have their changes take effect
|
226
180
|
#
|
227
|
-
#
|
181
|
+
# @return [Array<Hash>]
|
228
182
|
def valid_sets
|
229
|
-
sets =
|
183
|
+
sets = site.config["defaults"]
|
230
184
|
return [] unless sets.is_a?(Array)
|
231
185
|
|
232
186
|
sets.map do |set|
|
233
187
|
if valid?(set)
|
234
|
-
|
188
|
+
massage_scope!(set)
|
189
|
+
# TODO: is this trip really necessary?
|
190
|
+
ensure_time!(set)
|
235
191
|
else
|
236
192
|
Bridgetown.logger.warn "Defaults:", "An invalid front-matter default set was found:"
|
237
193
|
Bridgetown.logger.warn set.to_s
|
@@ -240,10 +196,18 @@ module Bridgetown
|
|
240
196
|
end.compact
|
241
197
|
end
|
242
198
|
|
243
|
-
#
|
199
|
+
# Set path to blank if not specified and alias older type to collection
|
200
|
+
def massage_scope!(set)
|
201
|
+
set["scope"] ||= {}
|
202
|
+
set["scope"]["path"] ||= ""
|
203
|
+
if set["scope"]["type"] && !set["scope"]["collection"]
|
204
|
+
set["scope"]["collection"] = set["scope"]["type"]
|
205
|
+
end
|
206
|
+
end
|
244
207
|
|
245
208
|
SANITIZATION_REGEX = %r!\A/|(?<=[^/])\z!.freeze
|
246
209
|
|
210
|
+
# Sanitizes the given path by removing a leading and adding a trailing slash
|
247
211
|
def sanitize_path(path)
|
248
212
|
if path.nil? || path.empty?
|
249
213
|
""
|