bridgetown-core 0.16.0.beta1 → 0.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.yardopts +1 -0
- data/bridgetown-core.gemspec +3 -1
- data/lib/bridgetown-core.rb +45 -29
- data/lib/bridgetown-core/collection.rb +5 -1
- data/lib/bridgetown-core/commands/apply.rb +2 -2
- data/lib/bridgetown-core/commands/concerns/actions.rb +2 -1
- data/lib/bridgetown-core/commands/console.rb +4 -4
- data/lib/bridgetown-core/commands/new.rb +1 -1
- data/lib/bridgetown-core/concerns/layout_placeable.rb +1 -1
- data/lib/bridgetown-core/concerns/liquid_renderable.rb +10 -0
- data/lib/bridgetown-core/concerns/site/configurable.rb +24 -22
- data/lib/bridgetown-core/concerns/site/content.rb +46 -33
- data/lib/bridgetown-core/concerns/site/extensible.rb +14 -13
- data/lib/bridgetown-core/concerns/site/localizable.rb +24 -0
- data/lib/bridgetown-core/concerns/site/processable.rb +12 -11
- data/lib/bridgetown-core/concerns/site/renderable.rb +35 -28
- data/lib/bridgetown-core/concerns/site/writable.rb +7 -15
- data/lib/bridgetown-core/concerns/validatable.rb +2 -2
- data/lib/bridgetown-core/configuration.rb +14 -6
- data/lib/bridgetown-core/converter.rb +0 -42
- data/lib/bridgetown-core/converters/erb_templates.rb +93 -17
- data/lib/bridgetown-core/converters/liquid_templates.rb +96 -0
- data/lib/bridgetown-core/converters/markdown.rb +0 -3
- data/lib/bridgetown-core/document.rb +34 -21
- data/lib/bridgetown-core/drops/site_drop.rb +5 -1
- data/lib/bridgetown-core/drops/unified_payload_drop.rb +0 -1
- data/lib/bridgetown-core/drops/url_drop.rb +19 -3
- data/lib/bridgetown-core/excerpt.rb +1 -1
- data/lib/bridgetown-core/filters.rb +37 -55
- data/lib/bridgetown-core/filters/condition_helpers.rb +56 -0
- data/lib/bridgetown-core/frontmatter_defaults.rb +17 -0
- data/lib/bridgetown-core/generators/prototype_generator.rb +42 -25
- data/lib/bridgetown-core/helpers.rb +84 -0
- data/lib/bridgetown-core/liquid_renderer.rb +1 -1
- data/lib/bridgetown-core/log_writer.rb +2 -2
- data/lib/bridgetown-core/page.rb +8 -2
- data/lib/bridgetown-core/plugin_manager.rb +44 -3
- data/lib/bridgetown-core/reader.rb +2 -4
- data/lib/bridgetown-core/readers/collection_reader.rb +1 -0
- data/lib/bridgetown-core/readers/data_reader.rb +4 -3
- data/lib/bridgetown-core/readers/defaults_reader.rb +27 -0
- data/lib/bridgetown-core/readers/layout_reader.rb +1 -0
- data/lib/bridgetown-core/readers/page_reader.rb +1 -0
- data/lib/bridgetown-core/readers/post_reader.rb +29 -15
- data/lib/bridgetown-core/readers/static_file_reader.rb +1 -0
- data/lib/bridgetown-core/renderer.rb +42 -160
- data/lib/bridgetown-core/ruby_template_view.rb +26 -8
- data/lib/bridgetown-core/site.rb +14 -2
- data/lib/bridgetown-core/tags/find.rb +86 -0
- data/lib/bridgetown-core/tags/t.rb +14 -0
- data/lib/bridgetown-core/tags/webpack_path.rb +6 -41
- data/lib/bridgetown-core/utils.rb +69 -2
- data/lib/bridgetown-core/utils/ruby_exec.rb +1 -1
- data/lib/bridgetown-core/version.rb +2 -2
- data/lib/bridgetown-core/watcher.rb +1 -0
- data/lib/site_template/src/_layouts/{default.html → default.liquid} +0 -0
- data/lib/site_template/src/_layouts/{home.html → home.liquid} +0 -0
- data/lib/site_template/src/_layouts/{page.html → page.liquid} +0 -0
- data/lib/site_template/src/_layouts/{post.html → post.liquid} +0 -0
- data/lib/site_template/src/images/.keep +1 -0
- metadata +47 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c36f73b0c33a2bf052be5e78359a241dce3034f144f9ff12bdd37515ba008f5a
|
4
|
+
data.tar.gz: fb6296ecf818c0fe40244359672babde4f4353549b4972ca5c112ff8ed8579bf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 52c7d713936d04fbcd76e0605d0eaf022800c3ca0ce3e5424630ff12486fa0cfdf786c693099211e2e2a5b2fe483a8eb1ab80a96eef92552397eaef348579ee8
|
7
|
+
data.tar.gz: 76d621f1fc7779830b15768ae21c37e95c5baf0a0949deb59d5d6677a35d68519d12a1bb05299c292420ca1062d73267acb944e77d88ae45b1a57499361c90b2
|
data/.yardopts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
-m markdown
|
data/bridgetown-core.gemspec
CHANGED
@@ -33,10 +33,12 @@ Gem::Specification.new do |s|
|
|
33
33
|
|
34
34
|
s.add_runtime_dependency("activesupport", "~> 6.0")
|
35
35
|
s.add_runtime_dependency("addressable", "~> 2.4")
|
36
|
-
s.add_runtime_dependency("
|
36
|
+
s.add_runtime_dependency("amazing_print", "~> 1.2")
|
37
37
|
s.add_runtime_dependency("colorator", "~> 1.0")
|
38
|
+
s.add_runtime_dependency("erubi", "~> 1.9")
|
38
39
|
s.add_runtime_dependency("faraday", "~> 1.0")
|
39
40
|
s.add_runtime_dependency("faraday_middleware", "~> 1.0")
|
41
|
+
s.add_runtime_dependency("hash_with_dot_access", "~> 1.0")
|
40
42
|
s.add_runtime_dependency("i18n", "~> 1.0")
|
41
43
|
s.add_runtime_dependency("kramdown", "~> 2.1")
|
42
44
|
s.add_runtime_dependency("kramdown-parser-gfm", "~> 1.0")
|
data/lib/bridgetown-core.rb
CHANGED
@@ -29,8 +29,9 @@ require "csv"
|
|
29
29
|
require "json"
|
30
30
|
|
31
31
|
# 3rd party
|
32
|
-
require "active_support/core_ext/
|
32
|
+
require "active_support/core_ext/object/blank"
|
33
33
|
require "active_support/core_ext/string/inflections"
|
34
|
+
require "hash_with_dot_access"
|
34
35
|
require "pathutil"
|
35
36
|
require "addressable/uri"
|
36
37
|
require "safe_yaml/load"
|
@@ -68,6 +69,7 @@ module Bridgetown
|
|
68
69
|
autoload :Cache, "bridgetown-core/cache"
|
69
70
|
autoload :CollectionReader, "bridgetown-core/readers/collection_reader"
|
70
71
|
autoload :DataReader, "bridgetown-core/readers/data_reader"
|
72
|
+
autoload :DefaultsReader, "bridgetown-core/readers/defaults_reader"
|
71
73
|
autoload :LayoutReader, "bridgetown-core/readers/layout_reader"
|
72
74
|
autoload :PostReader, "bridgetown-core/readers/post_reader"
|
73
75
|
autoload :PageReader, "bridgetown-core/readers/page_reader"
|
@@ -113,24 +115,23 @@ module Bridgetown
|
|
113
115
|
require_all "bridgetown-core/tags"
|
114
116
|
|
115
117
|
class << self
|
116
|
-
#
|
117
|
-
#
|
118
|
-
|
118
|
+
# Tells you which Bridgetown environment you are building in so
|
119
|
+
# you can skip tasks if you need to.
|
119
120
|
def environment
|
120
121
|
ENV["BRIDGETOWN_ENV"] || "development"
|
121
122
|
end
|
122
123
|
alias_method :env, :environment
|
123
124
|
|
124
|
-
#
|
125
|
-
#
|
126
|
-
#
|
125
|
+
# Generate a Bridgetown configuration hash by merging the default
|
126
|
+
# options with anything in bridgetown.config.yml, and adding the given
|
127
|
+
# options on top.
|
127
128
|
#
|
128
|
-
# override - A
|
129
|
-
#
|
130
|
-
#
|
131
|
-
#
|
129
|
+
# @param override [Hash] - A an optional hash of config directives that override
|
130
|
+
# any options in both the defaults and the config file. See
|
131
|
+
# {Bridgetown::Configuration::DEFAULTS} for a list of option names and their
|
132
|
+
# defaults.
|
132
133
|
#
|
133
|
-
#
|
134
|
+
# @return [Hash] The final configuration hash.
|
134
135
|
def configuration(override = {})
|
135
136
|
config = Configuration.new
|
136
137
|
override = Configuration[override].stringify_keys
|
@@ -145,15 +146,29 @@ module Bridgetown
|
|
145
146
|
end
|
146
147
|
|
147
148
|
# Conveinence method to register a new Thor command
|
149
|
+
#
|
150
|
+
# @see Bridgetown::Commands::Registrations.register
|
148
151
|
def register_command(&block)
|
149
152
|
Bridgetown::Commands::Registrations.register(&block)
|
150
153
|
end
|
151
154
|
|
152
|
-
#
|
155
|
+
# Determines the correct Bundler environment block method to use and passes
|
156
|
+
# the block on to it.
|
157
|
+
#
|
158
|
+
# @return [void]
|
159
|
+
def with_unbundled_env(&block)
|
160
|
+
if Bundler.bundler_major_version >= 2
|
161
|
+
Bundler.method(:with_unbundled_env).call(&block)
|
162
|
+
else
|
163
|
+
Bundler.method(:with_clean_env).call(&block)
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
# Set the TZ environment variable to use the timezone specified
|
153
168
|
#
|
154
|
-
# timezone
|
169
|
+
# @param timezone [String] the IANA Time Zone
|
155
170
|
#
|
156
|
-
#
|
171
|
+
# @return [void]
|
157
172
|
# rubocop:disable Naming/AccessorMethodName
|
158
173
|
def set_timezone(timezone)
|
159
174
|
ENV["TZ"] = if Utils::Platforms.really_windows?
|
@@ -164,38 +179,39 @@ module Bridgetown
|
|
164
179
|
end
|
165
180
|
# rubocop:enable Naming/AccessorMethodName
|
166
181
|
|
167
|
-
#
|
182
|
+
# Fetch the logger instance for this Bridgetown process.
|
168
183
|
#
|
169
|
-
#
|
184
|
+
# @return [LogAdapter]
|
170
185
|
def logger
|
171
186
|
@logger ||= LogAdapter.new(LogWriter.new, (ENV["BRIDGETOWN_LOG_LEVEL"] || :info).to_sym)
|
172
187
|
end
|
173
188
|
|
174
|
-
#
|
175
|
-
#
|
176
|
-
# as Ruby's interal Logger.
|
189
|
+
# Set the log writer. New log writer must respond to the same methods as Ruby's
|
190
|
+
# internal Logger.
|
177
191
|
#
|
178
|
-
# writer
|
192
|
+
# @param writer [Object] the new Logger-compatible log transport
|
179
193
|
#
|
180
|
-
#
|
194
|
+
# @return [LogAdapter]
|
181
195
|
def logger=(writer)
|
182
196
|
@logger = LogAdapter.new(writer, (ENV["BRIDGETOWN_LOG_LEVEL"] || :info).to_sym)
|
183
197
|
end
|
184
198
|
|
185
|
-
#
|
199
|
+
# An array of sites. Currently only ever a single entry.
|
186
200
|
#
|
187
|
-
#
|
201
|
+
# @return [Array<Bridgetown::Site>] the Bridgetown sites created.
|
188
202
|
def sites
|
189
203
|
@sites ||= []
|
190
204
|
end
|
191
205
|
|
192
|
-
#
|
193
|
-
#
|
206
|
+
# Ensures the questionable path is prefixed with the base directory
|
207
|
+
# and prepends the questionable path with the base directory if false.
|
194
208
|
#
|
195
|
-
# base_directory
|
196
|
-
#
|
209
|
+
# @param base_directory [String] the directory with which to prefix the
|
210
|
+
# questionable path
|
211
|
+
# @param questionable_path [String] the path we're unsure about, and want
|
212
|
+
# prefixed
|
197
213
|
#
|
198
|
-
#
|
214
|
+
# @return [String] the sanitized path
|
199
215
|
def sanitized_path(base_directory, questionable_path)
|
200
216
|
return base_directory if base_directory.eql?(questionable_path)
|
201
217
|
|
@@ -2,7 +2,10 @@
|
|
2
2
|
|
3
3
|
module Bridgetown
|
4
4
|
class Collection
|
5
|
-
|
5
|
+
# @return [Bridgetown::Site]
|
6
|
+
attr_reader :site
|
7
|
+
|
8
|
+
attr_reader :label, :metadata
|
6
9
|
attr_writer :docs
|
7
10
|
|
8
11
|
# Create a new Collection.
|
@@ -65,6 +68,7 @@ module Bridgetown
|
|
65
68
|
read_static_file(file_path, full_path)
|
66
69
|
end
|
67
70
|
end
|
71
|
+
site.static_files.concat(files)
|
68
72
|
sort_docs!
|
69
73
|
end
|
70
74
|
|
@@ -44,7 +44,7 @@ module Bridgetown
|
|
44
44
|
|
45
45
|
def apply_after_new_command
|
46
46
|
# Coming from the new command, so set up proper bundler env
|
47
|
-
|
47
|
+
Bridgetown.with_unbundled_env do
|
48
48
|
self.destination_root = New.created_site_dir
|
49
49
|
inside(New.created_site_dir) do
|
50
50
|
apply_from_url options[:apply]
|
@@ -62,7 +62,7 @@ module Bridgetown
|
|
62
62
|
" current folder."
|
63
63
|
end
|
64
64
|
|
65
|
-
|
65
|
+
Bridgetown.with_unbundled_env do
|
66
66
|
apply_from_url automation_command
|
67
67
|
end
|
68
68
|
rescue ArgumentError => e
|
@@ -11,6 +11,7 @@ module Bridgetown
|
|
11
11
|
GITHUB_REGEX = %r!https://github\.com!.freeze
|
12
12
|
GITHUB_TREE_REGEX = %r!#{GITHUB_REGEX}/.*/.*/tree/.*/?!.freeze
|
13
13
|
GITHUB_BLOB_REGEX = %r!#{GITHUB_REGEX}/.*/.*/blob/!.freeze
|
14
|
+
GITHUB_REPO_REGEX = %r!github\.com/(.*?/[^/]*)!.freeze
|
14
15
|
|
15
16
|
def create_builder(filename, data = nil)
|
16
17
|
say_status :create_builder, filename
|
@@ -114,7 +115,7 @@ module Bridgetown
|
|
114
115
|
elsif github_blob_match
|
115
116
|
new_url.sub("/blob/", "/")
|
116
117
|
else
|
117
|
-
"#{new_url}
|
118
|
+
"#{new_url}/#{Bridgetown::Utils.default_github_branch_name(arg)}"
|
118
119
|
end
|
119
120
|
else
|
120
121
|
arg
|
@@ -21,14 +21,14 @@ module Bridgetown
|
|
21
21
|
desc: "Custom configuration file(s)"
|
22
22
|
class_option :"bypass-ap",
|
23
23
|
type: :boolean,
|
24
|
-
desc: "Don't load
|
24
|
+
desc: "Don't load AmazingPrint when IRB opens"
|
25
25
|
class_option :blank,
|
26
26
|
type: :boolean,
|
27
27
|
desc: "Skip reading content and running generators before opening console"
|
28
28
|
|
29
29
|
def console
|
30
30
|
require "irb"
|
31
|
-
require "
|
31
|
+
require "amazing_print" unless options[:"bypass-ap"]
|
32
32
|
|
33
33
|
Bridgetown.logger.info "Starting:", "Bridgetown v#{Bridgetown::VERSION.magenta}" \
|
34
34
|
" (codename \"#{Bridgetown::CODE_NAME.yellow}\")" \
|
@@ -61,10 +61,10 @@ module Bridgetown
|
|
61
61
|
begin
|
62
62
|
catch(:IRB_EXIT) do
|
63
63
|
unless options[:"bypass-ap"]
|
64
|
-
|
64
|
+
AmazingPrint.defaults = {
|
65
65
|
indent: 2,
|
66
66
|
}
|
67
|
-
|
67
|
+
AmazingPrint.irb!
|
68
68
|
end
|
69
69
|
irb.eval_input
|
70
70
|
end
|
@@ -115,7 +115,7 @@ module Bridgetown
|
|
115
115
|
def bundle_install(path)
|
116
116
|
unless Bridgetown.environment == "test"
|
117
117
|
require "bundler"
|
118
|
-
|
118
|
+
Bridgetown.with_unbundled_env do
|
119
119
|
inside(path) do
|
120
120
|
run "bundle install", abort_on_failure: true
|
121
121
|
end
|
@@ -8,10 +8,20 @@ module Bridgetown
|
|
8
8
|
# contain any Liquid Tags or Variables, true otherwise.
|
9
9
|
def render_with_liquid?
|
10
10
|
return false if data["render_with_liquid"] == false
|
11
|
+
return false unless liquid_engine_configured?
|
11
12
|
|
12
13
|
!(yaml_file? || !Utils.has_liquid_construct?(content))
|
13
14
|
end
|
14
15
|
|
16
|
+
def liquid_engine_configured?
|
17
|
+
data["template_engine"] == "liquid" ||
|
18
|
+
(
|
19
|
+
data["template_engine"].nil? && (
|
20
|
+
site.config[:template_engine].nil? || site.config[:template_engine] == "liquid"
|
21
|
+
)
|
22
|
+
)
|
23
|
+
end
|
24
|
+
|
15
25
|
# Override in individual classes
|
16
26
|
def yaml_file?
|
17
27
|
false
|
@@ -1,18 +1,16 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
module
|
3
|
+
class Bridgetown::Site
|
4
|
+
module Configurable
|
5
5
|
# Set the site's configuration. This handles side-effects caused by
|
6
|
-
#
|
6
|
+
# changing values in the configuration.
|
7
7
|
#
|
8
|
-
# @param config [
|
9
|
-
# An instance of {
|
8
|
+
# @param config [Configuration]
|
9
|
+
# An instance of {Configuration},
|
10
10
|
# containing the new configuration.
|
11
11
|
#
|
12
|
-
# @return [
|
13
|
-
#
|
14
|
-
#
|
15
|
-
# @see Bridgetown::Configuration
|
12
|
+
# @return [Configuration]
|
13
|
+
# The processed instance of {Configuration}
|
16
14
|
def config=(config)
|
17
15
|
@config = config.clone
|
18
16
|
|
@@ -37,18 +35,22 @@ module Bridgetown
|
|
37
35
|
@config
|
38
36
|
end
|
39
37
|
|
38
|
+
def defaults_reader
|
39
|
+
@defaults_reader ||= Bridgetown::DefaultsReader.new(self)
|
40
|
+
end
|
41
|
+
|
40
42
|
# Returns the current instance of {FrontmatterDefaults} or
|
41
|
-
#
|
43
|
+
# creates a new instance {FrontmatterDefaults} if it doesn't already exist.
|
42
44
|
#
|
43
45
|
# @return [FrontmatterDefaults]
|
44
46
|
# Returns an instance of {FrontmatterDefaults}
|
45
47
|
def frontmatter_defaults
|
46
|
-
@frontmatter_defaults ||= FrontmatterDefaults.new(self)
|
48
|
+
@frontmatter_defaults ||= Bridgetown::FrontmatterDefaults.new(self)
|
47
49
|
end
|
48
50
|
|
49
51
|
# Whether to perform a full rebuild without incremental regeneration.
|
50
|
-
#
|
51
|
-
#
|
52
|
+
# If either `override["incremental"]` or `config["incremental"]` are true,
|
53
|
+
# fully rebuild the site. If not, incrementally build the site.
|
52
54
|
#
|
53
55
|
# @param [Hash] override
|
54
56
|
# An override hash to override the current config value
|
@@ -59,11 +61,11 @@ module Bridgetown
|
|
59
61
|
end
|
60
62
|
|
61
63
|
# Returns the current instance of {Publisher} or creates a new instance of
|
62
|
-
#
|
64
|
+
# {Publisher} if one doesn't exist.
|
63
65
|
#
|
64
66
|
# @return [Publisher] Returns an instance of {Publisher}
|
65
67
|
def publisher
|
66
|
-
@publisher ||= Publisher.new(self)
|
68
|
+
@publisher ||= Bridgetown::Publisher.new(self)
|
67
69
|
end
|
68
70
|
|
69
71
|
# Prefix a path or paths with the {#root_dir} directory.
|
@@ -122,16 +124,16 @@ module Bridgetown
|
|
122
124
|
end
|
123
125
|
|
124
126
|
# The full path to the directory that houses all the registered collections
|
125
|
-
#
|
127
|
+
# for the current site.
|
126
128
|
#
|
127
|
-
#
|
129
|
+
# If `@collections_path` is specified use its value.
|
128
130
|
#
|
129
|
-
#
|
130
|
-
#
|
131
|
-
#
|
131
|
+
# If `@collections` is not specified and `config["collections_dir"]` is
|
132
|
+
# specified, prepend it with {#source} and assign it to
|
133
|
+
# {#collections_path}.
|
132
134
|
#
|
133
|
-
#
|
134
|
-
#
|
135
|
+
# If `@collections` is not specified and `config["collections_dir"]` is not
|
136
|
+
# specified, assign {#source} to `@collections_path`
|
135
137
|
#
|
136
138
|
# @return [String] Returns the full path to the collections directory
|
137
139
|
# @see #config
|
@@ -1,27 +1,24 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
class Bridgetown::Site
|
4
|
+
# Content is king!
|
5
|
+
module Content
|
5
6
|
# Construct a Hash of Posts indexed by the specified Post attribute.
|
6
7
|
#
|
7
|
-
#
|
8
|
-
#
|
9
|
-
# @example
|
10
|
-
# Returns a hash like so: { attr => posts } where
|
8
|
+
# Returns a hash like so: `{ attr => posts }` where:
|
11
9
|
#
|
12
|
-
#
|
10
|
+
# * `attr` - One of the values for the requested attribute.
|
11
|
+
# * `posts` - The array of Posts with the given attr value.
|
13
12
|
#
|
14
|
-
#
|
13
|
+
# @param post_attr [String] The String name of the Post attribute.
|
15
14
|
#
|
16
15
|
# @example
|
17
|
-
#
|
18
16
|
# post_attr_hash('categories')
|
19
17
|
# # => { 'tech' => [<Post A>, <Post B>],
|
20
18
|
# # 'ruby' => [<Post B>] }
|
21
19
|
#
|
22
20
|
# @return [Hash{String, Symbol => Array<Post>}]
|
23
21
|
# Returns a hash of !{attr => posts}
|
24
|
-
#
|
25
22
|
def post_attr_hash(post_attr)
|
26
23
|
# Build a hash map based on the specified post attribute ( post attr =>
|
27
24
|
# array of posts ) then sort each array in reverse order.
|
@@ -36,7 +33,7 @@ module Bridgetown
|
|
36
33
|
end
|
37
34
|
|
38
35
|
# Returns a hash of "tags" using {#post_attr_hash} where each tag is a key
|
39
|
-
#
|
36
|
+
# and each value is a post which contains the key.
|
40
37
|
# @example
|
41
38
|
# tags
|
42
39
|
# # => { 'tech': [<Post A>, <Post B>],
|
@@ -48,7 +45,7 @@ module Bridgetown
|
|
48
45
|
end
|
49
46
|
|
50
47
|
# Returns a hash of "categories" using {#post_attr_hash} where each tag is
|
51
|
-
#
|
48
|
+
# a key and each value is a post which contains the key.
|
52
49
|
# @example
|
53
50
|
# categories
|
54
51
|
# # => { 'tech': [<Post A>, <Post B>],
|
@@ -60,11 +57,11 @@ module Bridgetown
|
|
60
57
|
post_attr_hash("categories")
|
61
58
|
end
|
62
59
|
|
63
|
-
# Returns the value of
|
64
|
-
#
|
60
|
+
# Returns the value of `data["site_metadata"]` or creates a new instance of
|
61
|
+
# `HashWithDotAccess::Hash`
|
65
62
|
# @return [Hash] Returns a hash of site metadata
|
66
63
|
def metadata
|
67
|
-
data["site_metadata"] ||=
|
64
|
+
data["site_metadata"] ||= HashWithDotAccess::Hash.new
|
68
65
|
end
|
69
66
|
|
70
67
|
# The Hash payload containing site-wide data.
|
@@ -98,34 +95,33 @@ module Bridgetown
|
|
98
95
|
#
|
99
96
|
# @see #post_attr_hash
|
100
97
|
def site_payload
|
101
|
-
Drops::UnifiedPayloadDrop.new self
|
98
|
+
Bridgetown::Drops::UnifiedPayloadDrop.new self
|
102
99
|
end
|
103
100
|
alias_method :to_liquid, :site_payload
|
104
101
|
|
105
|
-
# The list of
|
102
|
+
# The list of collections labels and their corresponding {Collection} instances.
|
106
103
|
#
|
107
|
-
#
|
108
|
-
#
|
104
|
+
# If `config['collections']` is set, a new instance of {Collection} is created
|
105
|
+
# for each entry in the collections configuration.
|
109
106
|
#
|
110
|
-
#
|
107
|
+
# If `config["collections"]` is not specified, a blank hash is returned.
|
111
108
|
#
|
112
|
-
# @return [Hash{String, Symbol =>
|
109
|
+
# @return [Hash{String, Symbol => Collection}] A Hash
|
113
110
|
# containing a collection name-to-instance pairs.
|
114
111
|
#
|
115
112
|
# @return [Hash] Returns a blank hash if no items found
|
116
|
-
# @see Collection
|
117
113
|
def collections
|
118
114
|
@collections ||= collection_names.each_with_object(
|
119
|
-
|
115
|
+
HashWithDotAccess::Hash.new
|
120
116
|
) do |name, hsh|
|
121
117
|
hsh[name] = Bridgetown::Collection.new(self, name)
|
122
118
|
end
|
123
119
|
end
|
124
120
|
|
125
121
|
# An array of collection names.
|
126
|
-
# @return [Array<
|
127
|
-
# or an empty array if the
|
128
|
-
# @raise ArgumentError Raise an error if
|
122
|
+
# @return [Array<String>] an array of collection names from the configuration,
|
123
|
+
# or an empty array if the `config["collections"]` key is not set.
|
124
|
+
# @raise ArgumentError Raise an error if `config["collections"]` is not
|
129
125
|
# an Array or a Hash
|
130
126
|
def collection_names
|
131
127
|
case config["collections"]
|
@@ -141,17 +137,18 @@ module Bridgetown
|
|
141
137
|
end
|
142
138
|
|
143
139
|
# Get all documents.
|
144
|
-
# @return [Array<
|
140
|
+
# @return [Array<Document>] an array of documents from the
|
141
|
+
# configuration
|
145
142
|
def documents
|
146
143
|
collections.each_with_object(Set.new) do |(_, collection), set|
|
147
|
-
set.merge(collection.docs)
|
144
|
+
set.merge(collection.docs)
|
148
145
|
end.to_a
|
149
146
|
end
|
150
147
|
|
151
148
|
# Get the documents to be written
|
152
149
|
#
|
153
|
-
# @return [Array<
|
154
|
-
# that
|
150
|
+
# @return [Array<Document>] an array of documents which should be
|
151
|
+
# written and that `respond_to :write?`
|
155
152
|
# @see #documents
|
156
153
|
# @see Collection
|
157
154
|
def docs_to_write
|
@@ -160,11 +157,27 @@ module Bridgetown
|
|
160
157
|
|
161
158
|
# Get all posts.
|
162
159
|
#
|
163
|
-
# @return [Collection]
|
164
|
-
# @return [Collection] Return a new #Collection if +#collections+["posts"] is nil
|
160
|
+
# @return [Collection] Returns {#collections}`["posts"]`, creating it if need be
|
165
161
|
# @see Collection
|
166
162
|
def posts
|
167
|
-
collections["posts"] ||= Collection.new(self, "posts")
|
163
|
+
collections["posts"] ||= Bridgetown::Collection.new(self, "posts")
|
164
|
+
end
|
165
|
+
|
166
|
+
# Get the static files to be written
|
167
|
+
#
|
168
|
+
# @return [Array<StaticFile>] an array of files which should be
|
169
|
+
# written and that `respond_to :write?`
|
170
|
+
# @see #static_files
|
171
|
+
# @see StaticFile
|
172
|
+
def static_files_to_write
|
173
|
+
static_files.select(&:write?)
|
174
|
+
end
|
175
|
+
|
176
|
+
# Get all pages and documents (posts and collection items) in a single array.
|
177
|
+
#
|
178
|
+
# @return [Array]
|
179
|
+
def contents
|
180
|
+
pages + documents
|
168
181
|
end
|
169
182
|
end
|
170
183
|
end
|