bridgetown-core 2.0.0.beta2 → 2.0.0.beta4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +3 -0
- data/bridgetown-core.gemspec +43 -42
- data/lib/bridgetown-core/cache.rb +3 -19
- data/lib/bridgetown-core/cleaner.rb +17 -19
- data/lib/bridgetown-core/collection.rb +6 -5
- data/lib/bridgetown-core/commands/base.rb +7 -0
- data/lib/bridgetown-core/commands/build.rb +35 -22
- data/lib/bridgetown-core/commands/concerns/actions.rb +4 -0
- data/lib/bridgetown-core/commands/console.rb +0 -1
- data/lib/bridgetown-core/commands/esbuild/esbuild.config.js +7 -6
- data/lib/bridgetown-core/commands/esbuild/esbuild.defaults.js.erb +14 -13
- data/lib/bridgetown-core/commands/esbuild/migrate-from-webpack.rb +1 -1
- data/lib/bridgetown-core/commands/esbuild/update.rb +17 -3
- data/lib/bridgetown-core/commands/esbuild.rb +1 -1
- data/lib/bridgetown-core/commands/start.rb +12 -2
- data/lib/bridgetown-core/component.rb +1 -1
- data/lib/bridgetown-core/concerns/intuitive_expectations.rb +67 -0
- data/lib/bridgetown-core/concerns/layout_placeable.rb +1 -1
- data/lib/bridgetown-core/concerns/publishable.rb +2 -0
- data/lib/bridgetown-core/concerns/site/content.rb +4 -1
- data/lib/bridgetown-core/concerns/site/extensible.rb +6 -1
- data/lib/bridgetown-core/concerns/site/fast_refreshable.rb +33 -18
- data/lib/bridgetown-core/concerns/site/localizable.rb +2 -0
- data/lib/bridgetown-core/concerns/site/processable.rb +2 -0
- data/lib/bridgetown-core/concerns/site/renderable.rb +3 -0
- data/lib/bridgetown-core/concerns/site/ssr.rb +1 -2
- data/lib/bridgetown-core/concerns/site/writable.rb +1 -0
- data/lib/bridgetown-core/concerns/viewable.rb +46 -0
- data/lib/bridgetown-core/configuration.rb +29 -23
- data/lib/bridgetown-core/configurations/gh-pages/gh-pages.yml +5 -5
- data/lib/bridgetown-core/configurations/minitesting.rb +24 -64
- data/lib/bridgetown-core/converter.rb +2 -7
- data/lib/bridgetown-core/converters/erb_templates.rb +11 -7
- data/lib/bridgetown-core/converters/identity.rb +3 -11
- data/lib/bridgetown-core/converters/liquid_templates.rb +3 -5
- data/lib/bridgetown-core/converters/markdown/kramdown_parser.rb +1 -1
- data/lib/bridgetown-core/converters/markdown.rb +11 -14
- data/lib/bridgetown-core/converters/serbea_templates.rb +10 -8
- data/lib/bridgetown-core/drops/drop.rb +29 -42
- data/lib/bridgetown-core/drops/resource_drop.rb +3 -12
- data/lib/bridgetown-core/errors.rb +2 -8
- data/lib/bridgetown-core/filters/condition_helpers.rb +6 -9
- data/lib/bridgetown-core/filters/date_filters.rb +22 -35
- data/lib/bridgetown-core/filters/grouping_filters.rb +11 -11
- data/lib/bridgetown-core/filters.rb +53 -72
- data/lib/bridgetown-core/front_matter/defaults.rb +14 -19
- data/lib/bridgetown-core/generated_page.rb +6 -6
- data/lib/bridgetown-core/generators/prototype_generator.rb +0 -2
- data/lib/bridgetown-core/helpers.rb +2 -2
- data/lib/bridgetown-core/hooks.rb +0 -1
- data/lib/bridgetown-core/layout.rb +3 -4
- data/lib/bridgetown-core/liquid_extensions.rb +3 -5
- data/lib/bridgetown-core/log_adapter.rb +37 -56
- data/lib/bridgetown-core/plugin_manager.rb +7 -3
- data/lib/bridgetown-core/rack/boot.rb +7 -57
- data/lib/bridgetown-core/rack/default_config.ru +14 -0
- data/lib/bridgetown-core/rack/loader_hooks.rb +83 -0
- data/lib/bridgetown-core/rack/logger.rb +0 -2
- data/lib/bridgetown-core/rack/routes.rb +3 -2
- data/lib/bridgetown-core/resource/base.rb +8 -8
- data/lib/bridgetown-core/resource/permalink_processor.rb +1 -1
- data/lib/bridgetown-core/resource/relations.rb +3 -1
- data/lib/bridgetown-core/ruby_template_view.rb +0 -1
- data/lib/bridgetown-core/static_file.rb +15 -20
- data/lib/bridgetown-core/tags/class_map.rb +1 -1
- data/lib/bridgetown-core/tags/post_url.rb +2 -32
- data/lib/bridgetown-core/utils/initializers.rb +2 -2
- data/lib/bridgetown-core/utils/require_gems.rb +1 -3
- data/lib/bridgetown-core/utils.rb +41 -44
- data/lib/bridgetown-core/watcher.rb +2 -3
- data/lib/bridgetown-core.rb +29 -10
- data/lib/roda/plugins/bridgetown_server.rb +13 -25
- data/lib/roda/plugins/bridgetown_ssr.rb +21 -3
- data/lib/roda/plugins/flashier.rb +57 -0
- data/lib/roda/plugins/generic_index.html +127 -0
- data/lib/roda/plugins/ssg.rb +3 -2
- data/lib/site_template/config/initializers.rb +2 -0
- data/lib/site_template/package.json.erb +1 -0
- data/lib/site_template/postcss.config.js.erb +1 -1
- metadata +26 -7
- data/lib/bridgetown-core/commands/doctor.rb +0 -147
@@ -11,23 +11,19 @@ module Bridgetown
|
|
11
11
|
error: ::Logger::ERROR,
|
12
12
|
}.freeze
|
13
13
|
|
14
|
-
#
|
14
|
+
# Create a new instance of a log writer
|
15
15
|
#
|
16
|
-
# writer
|
17
|
-
# log_level
|
18
|
-
#
|
19
|
-
# Returns nothing
|
16
|
+
# @param writer [Logger] compatible instance
|
17
|
+
# @param log_level [Symbol] the log level (`debug` | `info` | `warn` | `error`)
|
20
18
|
def initialize(writer, level = :info)
|
21
19
|
@messages = []
|
22
20
|
@writer = writer
|
23
21
|
self.log_level = level
|
24
22
|
end
|
25
23
|
|
26
|
-
#
|
27
|
-
#
|
28
|
-
# level - (symbol) the log level
|
24
|
+
# Set the log level on the writer
|
29
25
|
#
|
30
|
-
#
|
26
|
+
# @param log_level [Symbol] the log level (`debug` | `info` | `warn` | `error`)
|
31
27
|
def log_level=(level)
|
32
28
|
writer.level = level if level.is_a?(Integer) && level.between?(0, 3)
|
33
29
|
writer.level = LOG_LEVELS[level] ||
|
@@ -45,63 +41,52 @@ module Bridgetown
|
|
45
41
|
debug "Logging at level:", LOG_LEVELS.key(writer.level).to_s
|
46
42
|
end
|
47
43
|
|
48
|
-
#
|
49
|
-
#
|
50
|
-
# topic - the topic of the message, e.g. "Configuration file", "Deprecation", etc.
|
51
|
-
# message - the message detail
|
44
|
+
# Print a debug message
|
52
45
|
#
|
53
|
-
#
|
46
|
+
# @param topic [String] e.g. "Configuration file", "Deprecation", etc.
|
47
|
+
# @param message [String] the message detail
|
54
48
|
def debug(topic, message = nil, &)
|
55
49
|
write(:debug, topic, message, &)
|
56
50
|
end
|
57
51
|
|
58
|
-
#
|
52
|
+
# Print an informational message
|
59
53
|
#
|
60
|
-
#
|
61
|
-
# message
|
62
|
-
#
|
63
|
-
# Returns nothing
|
54
|
+
# @param topic [String] e.g. "Configuration file", "Deprecation", etc.
|
55
|
+
# @param message [String] the message detail
|
64
56
|
def info(topic, message = nil, &)
|
65
57
|
write(:info, topic, message, &)
|
66
58
|
end
|
67
59
|
|
68
|
-
#
|
69
|
-
#
|
70
|
-
# topic - the topic of the message, e.g. "Configuration file", "Deprecation", etc.
|
71
|
-
# message - the message detail
|
60
|
+
# Print a warning message
|
72
61
|
#
|
73
|
-
#
|
62
|
+
# @param topic [String] e.g. "Configuration file", "Deprecation", etc.
|
63
|
+
# @param message [String] the message detail
|
74
64
|
def warn(topic, message = nil, &)
|
75
65
|
write(:warn, topic, message, &)
|
76
66
|
end
|
77
67
|
|
78
|
-
#
|
79
|
-
#
|
80
|
-
# topic - the topic of the message, e.g. "Configuration file", "Deprecation", etc.
|
81
|
-
# message - the message detail
|
68
|
+
# Print an error message
|
82
69
|
#
|
83
|
-
#
|
70
|
+
# @param topic [String] e.g. "Configuration file", "Deprecation", etc.
|
71
|
+
# @param message [String] the message detail
|
84
72
|
def error(topic, message = nil, &)
|
85
73
|
write(:error, topic, message, &)
|
86
74
|
end
|
87
75
|
|
88
|
-
#
|
76
|
+
# Print an error message and immediately abort the process
|
89
77
|
#
|
90
|
-
#
|
91
|
-
# message
|
92
|
-
#
|
93
|
-
# Returns nothing
|
78
|
+
# @param topic [String] e.g. "Configuration file", "Deprecation", etc.
|
79
|
+
# @param message [String] the message detail
|
94
80
|
def abort_with(topic, message = nil, &)
|
95
81
|
error(topic, message, &)
|
96
82
|
abort
|
97
83
|
end
|
98
84
|
|
99
|
-
#
|
100
|
-
#
|
101
|
-
# topic - the topic of the message, e.g. "Configuration file", "Deprecation", etc.
|
102
|
-
# message - the message detail
|
85
|
+
# Build a topic method
|
103
86
|
#
|
104
|
-
#
|
87
|
+
# @param topic [String] e.g. "Configuration file", "Deprecation", etc.
|
88
|
+
# @param message [String] the message detail
|
89
|
+
# @return [String] the formatted message
|
105
90
|
def message(topic, message = nil)
|
106
91
|
raise ArgumentError, "block or message, not both" if block_given? && message
|
107
92
|
|
@@ -113,34 +98,30 @@ module Bridgetown
|
|
113
98
|
out
|
114
99
|
end
|
115
100
|
|
116
|
-
#
|
117
|
-
#
|
118
|
-
# topic - the topic of the message, e.g. "Configuration file", "Deprecation", etc.
|
119
|
-
# colon -
|
101
|
+
# Format the topic
|
120
102
|
#
|
121
|
-
#
|
103
|
+
# @param topic [String] e.g. "Configuration file", "Deprecation", etc.
|
104
|
+
# @param colon [Boolean]
|
105
|
+
# @return [String] formatted topic statement
|
122
106
|
def formatted_topic(topic, colon = false) # rubocop:disable Style/OptionalBooleanParameter
|
123
107
|
"#{topic}#{colon ? ": " : " "}".rjust(20)
|
124
108
|
end
|
125
109
|
|
126
|
-
#
|
110
|
+
# Check if the message should be written given the log level
|
127
111
|
#
|
128
|
-
# level_of_message
|
129
|
-
#
|
130
|
-
# Returns whether the message should be written.
|
112
|
+
# @param level_of_message [Symbol] the message level (`debug` | `info` | `warn` | `error`)
|
113
|
+
# @return [Boolean] whether the message should be written to the log
|
131
114
|
def write_message?(level_of_message)
|
132
115
|
LOG_LEVELS.fetch(level) <= LOG_LEVELS.fetch(level_of_message)
|
133
116
|
end
|
134
117
|
|
135
|
-
#
|
136
|
-
#
|
137
|
-
# level_of_message - the Symbol level of message, one of :debug, :info, :warn, :error
|
138
|
-
# topic - the String topic or full message
|
139
|
-
# message - the String message (optional)
|
140
|
-
# block - a block containing the message (optional)
|
118
|
+
# Log a message. If a block is provided containing the message, use that instead.
|
141
119
|
#
|
142
|
-
#
|
143
|
-
#
|
120
|
+
# @param level_of_message [Symbol] the message level (`debug` | `info` | `warn` | `error`)
|
121
|
+
# @param topic [String] e.g. "Configuration file", "Deprecation", etc.
|
122
|
+
# @param message [String] the message detail
|
123
|
+
# @return [BasicObject] false if the message was not written, otherwise returns the value of
|
124
|
+
# calling the appropriate writer method, e.g. writer.info.
|
144
125
|
def write(level_of_message, topic, message = nil, &)
|
145
126
|
return false unless write_message?(level_of_message)
|
146
127
|
|
@@ -81,12 +81,12 @@ module Bridgetown
|
|
81
81
|
end
|
82
82
|
|
83
83
|
def self.package_manager
|
84
|
-
@package_manager ||= if File.exist?("
|
85
|
-
"npm"
|
86
|
-
elsif File.exist?("yarn.lock")
|
84
|
+
@package_manager ||= if File.exist?("yarn.lock")
|
87
85
|
"yarn"
|
88
86
|
elsif File.exist?("pnpm-lock.yaml")
|
89
87
|
"pnpm"
|
88
|
+
elsif File.exist?("package.json")
|
89
|
+
"npm"
|
90
90
|
else
|
91
91
|
""
|
92
92
|
end
|
@@ -96,6 +96,10 @@ module Bridgetown
|
|
96
96
|
package_manager == "npm" ? "install" : "add"
|
97
97
|
end
|
98
98
|
|
99
|
+
def self.package_manager_uninstall_command
|
100
|
+
package_manager == "npm" ? "uninstall" : "remove"
|
101
|
+
end
|
102
|
+
|
99
103
|
# rubocop:disable Metrics/PerceivedComplexity, Metrics/CyclomaticComplexity
|
100
104
|
|
101
105
|
# Iterates through loaded gems and finds npm-add gemspec metadata.
|
@@ -3,14 +3,16 @@
|
|
3
3
|
require "zeitwerk"
|
4
4
|
require "roda"
|
5
5
|
require "json"
|
6
|
+
require "bridgetown"
|
6
7
|
|
7
|
-
|
8
|
-
|
8
|
+
require_relative "loader_hooks"
|
9
9
|
require_relative "logger"
|
10
10
|
require_relative "routes"
|
11
11
|
|
12
12
|
module Bridgetown
|
13
13
|
module Rack
|
14
|
+
Bridgetown.begin!(with_config: :initializers)
|
15
|
+
|
14
16
|
class << self
|
15
17
|
# @return [Bridgetown::Utils::LoadersManager]
|
16
18
|
attr_accessor :loaders_manager
|
@@ -23,61 +25,9 @@ module Bridgetown
|
|
23
25
|
self.loaders_manager =
|
24
26
|
Bridgetown::Utils::LoadersManager.new(Bridgetown::Current.preloaded_configuration)
|
25
27
|
Bridgetown::Current.preloaded_configuration.run_initializers! context: :server
|
26
|
-
autoload_server_folder
|
27
|
-
|
28
|
-
|
29
|
-
raise Bridgetown::Errors::InvalidConfigurationError,
|
30
|
-
"The Roda sessions plugin can't find a valid secret. Run `bin/bridgetown secret' " \
|
31
|
-
"and put the key in a ENV var you can use to configure the session in the Roda app"
|
32
|
-
end
|
33
|
-
|
34
|
-
raise e
|
35
|
-
end
|
36
|
-
|
37
|
-
# @param root [String] root of Bridgetown site, defaults to config value
|
38
|
-
def self.autoload_server_folder( # rubocop:todo Metrics
|
39
|
-
root: Bridgetown::Current.preloaded_configuration.root_dir
|
40
|
-
)
|
41
|
-
server_folder = File.join(root, "server")
|
42
|
-
|
43
|
-
Bridgetown::Hooks.register_one(
|
44
|
-
:loader, :post_setup, reloadable: false
|
45
|
-
) do |loader, load_path|
|
46
|
-
next unless load_path == server_folder
|
47
|
-
|
48
|
-
loader.eager_load
|
49
|
-
loader.do_not_eager_load(File.join(server_folder, "roda_app.rb"))
|
50
|
-
|
51
|
-
unless ENV["BRIDGETOWN_ENV"] == "production"
|
52
|
-
Listen.to(server_folder) do |modified, added, removed|
|
53
|
-
c = modified + added + removed
|
54
|
-
n = c.length
|
55
|
-
|
56
|
-
Bridgetown.logger.info(
|
57
|
-
"Reloading…",
|
58
|
-
"#{n} file#{"s" if n > 1} changed at #{Time.now.strftime("%Y-%m-%d %H:%M:%S")}"
|
59
|
-
)
|
60
|
-
c.each do |path|
|
61
|
-
Bridgetown.logger.info "", "- #{path["#{File.dirname(server_folder)}/".length..]}"
|
62
|
-
end
|
63
|
-
|
64
|
-
loader.reload
|
65
|
-
loader.eager_load
|
66
|
-
rescue SyntaxError => e
|
67
|
-
Bridgetown::Errors.print_build_error(e)
|
68
|
-
end.start
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
Bridgetown::Hooks.register_one(
|
73
|
-
:loader, :post_reload, reloadable: false
|
74
|
-
) do |loader, load_path|
|
75
|
-
next unless load_path == server_folder
|
76
|
-
|
77
|
-
loader.eager_load
|
78
|
-
end
|
79
|
-
|
80
|
-
loaders_manager.setup_loaders([server_folder])
|
28
|
+
LoaderHooks.autoload_server_folder(
|
29
|
+
File.join(Bridgetown::Current.preloaded_configuration.root_dir, "server")
|
30
|
+
)
|
81
31
|
end
|
82
32
|
end
|
83
33
|
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Bridgetown
|
4
|
+
module Rack
|
5
|
+
module LoaderHooks
|
6
|
+
# Sets up a Zeitwerk loader for the Roda routes in the server folder. Called by the server
|
7
|
+
# boot process when Rack starts up
|
8
|
+
#
|
9
|
+
# @param server_folder [String] typically `server` within the site root
|
10
|
+
def self.autoload_server_folder(server_folder)
|
11
|
+
reload_file_path = Bridgetown.live_reload_path
|
12
|
+
|
13
|
+
register_hooks server_folder, reload_file_path
|
14
|
+
|
15
|
+
Bridgetown::Rack.loaders_manager.setup_loaders([server_folder])
|
16
|
+
end
|
17
|
+
|
18
|
+
# Registers a `post_setup` and `post_reload` hook for the Zeitwerk loader in order to handle
|
19
|
+
# eager loading and, in development, the live reload watcher
|
20
|
+
#
|
21
|
+
# @param server_folder [String]
|
22
|
+
# @param reload_file_path [String] path to the special live reload txt file
|
23
|
+
def self.register_hooks(server_folder, reload_file_path) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/MethodLength
|
24
|
+
Bridgetown::Hooks.register_one(
|
25
|
+
:loader, :post_setup, reloadable: false
|
26
|
+
) do |loader, load_path|
|
27
|
+
next unless load_path == server_folder
|
28
|
+
|
29
|
+
loader.eager_load
|
30
|
+
subclass_names = Roda.subclasses.map(&:name)
|
31
|
+
subclass_paths = Set.new
|
32
|
+
|
33
|
+
loader.all_expected_cpaths.each do |cpath, cname|
|
34
|
+
if subclass_names.include?(cname) && cpath.start_with?(server_folder)
|
35
|
+
subclass_paths << cpath
|
36
|
+
loader.do_not_eager_load cpath
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
unless ENV["BRIDGETOWN_ENV"] == "production"
|
41
|
+
setup_autoload_listener loader, server_folder, subclass_paths
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
Bridgetown::Hooks.register_one(
|
46
|
+
:loader, :post_reload, reloadable: false
|
47
|
+
) do |loader, load_path|
|
48
|
+
next unless load_path == server_folder
|
49
|
+
|
50
|
+
loader.eager_load
|
51
|
+
Bridgetown.touch_live_reload_file(reload_file_path)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
# Creates a listener to detect file changes within the server folder and notify Zeitwerk
|
56
|
+
#
|
57
|
+
# @param loader [Zeitwerk::Loader]
|
58
|
+
# @param server_loader [String]
|
59
|
+
# @param subclass_paths [Array<string>]
|
60
|
+
def self.setup_autoload_listener(loader, server_folder, subclass_paths)
|
61
|
+
Listen.to(server_folder) do |modified, added, removed|
|
62
|
+
c = modified + added + removed
|
63
|
+
n = c.length
|
64
|
+
|
65
|
+
unless n == 1 && subclass_paths.include?(c.first)
|
66
|
+
Bridgetown.logger.info(
|
67
|
+
"Reloading…",
|
68
|
+
"#{n} file#{"s" if n > 1} changed at #{Time.now.strftime("%Y-%m-%d %H:%M:%S")}"
|
69
|
+
)
|
70
|
+
c.each do |path|
|
71
|
+
Bridgetown.logger.info "", "- #{path["#{File.dirname(server_folder)}/".length..]}"
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
loader.reload
|
76
|
+
Bridgetown::Hooks.trigger :loader, :post_reload, loader, server_folder
|
77
|
+
rescue SyntaxError => e
|
78
|
+
Bridgetown::Errors.print_build_error(e)
|
79
|
+
end.start
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
@@ -101,13 +101,14 @@ module Bridgetown
|
|
101
101
|
Bridgetown::Rack::Routes.sorted_subclasses&.each do |klass|
|
102
102
|
klass.merge roda_app
|
103
103
|
end
|
104
|
+
|
105
|
+
nil # required for proper 404 handling
|
104
106
|
end
|
105
107
|
|
106
108
|
# @param app [Roda]
|
107
109
|
def setup_live_reload(app) # rubocop:disable Metrics
|
108
110
|
sleep_interval = 0.5
|
109
|
-
file_to_check =
|
110
|
-
"index.html")
|
111
|
+
file_to_check = Bridgetown.live_reload_path
|
111
112
|
errors_file = Bridgetown.build_errors_path
|
112
113
|
|
113
114
|
app.request.get "_bridgetown/live_reload" do
|
@@ -106,11 +106,7 @@ module Bridgetown
|
|
106
106
|
#
|
107
107
|
# @param new_data [HashWithDotAccess::Hash]
|
108
108
|
def data=(new_data)
|
109
|
-
if site.config.fast_refresh && write?
|
110
|
-
# TODO: investigate if this would be better:
|
111
|
-
# @data.value = front_matter_defaults
|
112
|
-
mark_for_fast_refresh!
|
113
|
-
end
|
109
|
+
mark_for_fast_refresh! if site.config.fast_refresh && write?
|
114
110
|
|
115
111
|
Signalize.batch do
|
116
112
|
@content_signal.value += 1
|
@@ -221,12 +217,12 @@ module Bridgetown
|
|
221
217
|
|
222
218
|
# @return [String]
|
223
219
|
def absolute_url
|
224
|
-
format_url
|
220
|
+
@absolute_url ||= format_url(destination&.absolute_url)
|
225
221
|
end
|
226
222
|
|
227
223
|
# @return [String]
|
228
224
|
def relative_url
|
229
|
-
format_url
|
225
|
+
@relative_url ||= format_url(destination&.relative_url)
|
230
226
|
end
|
231
227
|
|
232
228
|
# @return [String]
|
@@ -365,7 +361,11 @@ module Bridgetown
|
|
365
361
|
past_values = @data.peek.select do |key|
|
366
362
|
key == "categories" || key == "tags" || site.taxonomy_types.keys.any?(key)
|
367
363
|
end
|
368
|
-
|
364
|
+
origin_data = model.origin.read
|
365
|
+
correct_locale = origin_data["locale"] || origin_data[:locale] || data.locale
|
366
|
+
model.attributes = origin_data
|
367
|
+
model.attributes.locale = correct_locale
|
368
|
+
@relative_url = @absolute_url = nil # wipe memoizations
|
369
369
|
read!
|
370
370
|
tax_diff = past_values.any? { |k, v| @data.peek[k] != v }
|
371
371
|
|
@@ -120,7 +120,7 @@ module Bridgetown
|
|
120
120
|
end
|
121
121
|
|
122
122
|
# @param resource [Bridgetown::Resource::Base]
|
123
|
-
register_placeholder :name, ->(resource) do
|
123
|
+
register_placeholder :name, ->(resource) do # rubocop:disable Style/SymbolProc
|
124
124
|
resource.basename_without_ext
|
125
125
|
end
|
126
126
|
|
@@ -20,7 +20,9 @@ module Bridgetown
|
|
20
20
|
|
21
21
|
# @return [HashWithDotAccess::Hash]
|
22
22
|
def relation_schema
|
23
|
-
resource.collection.metadata.relations
|
23
|
+
@relation_schema ||= resource.collection.metadata.relations&.transform_values do |value|
|
24
|
+
value.is_a?(Array) ? value.map(&:to_s) : value.to_s
|
25
|
+
end
|
24
26
|
end
|
25
27
|
|
26
28
|
# @return [Array<String>]
|
@@ -131,7 +131,6 @@ module Bridgetown
|
|
131
131
|
def _partial_path(partial_name, ext)
|
132
132
|
partial_name = partial_name.split("/").tap { _1.last.prepend("_") }.join("/")
|
133
133
|
|
134
|
-
# TODO: see if there's a workaround for this to speed up performance
|
135
134
|
site.in_source_dir(site.config[:partials_dir], "#{partial_name}.#{ext}")
|
136
135
|
end
|
137
136
|
end
|
@@ -48,11 +48,10 @@ module Bridgetown
|
|
48
48
|
@path ||= File.join(*[@base, @dir, @name].compact)
|
49
49
|
end
|
50
50
|
|
51
|
-
# Obtain destination path
|
51
|
+
# Obtain destination path
|
52
52
|
#
|
53
|
-
# dest
|
54
|
-
#
|
55
|
-
# Returns destination file path.
|
53
|
+
# @param dest [String] path to the destination dir
|
54
|
+
# @return [String]
|
56
55
|
def destination(dest)
|
57
56
|
dest = site.in_dest_dir(dest)
|
58
57
|
dest_url = url
|
@@ -76,22 +75,21 @@ module Bridgetown
|
|
76
75
|
|
77
76
|
alias_method :date, :modified_time
|
78
77
|
|
79
|
-
#
|
78
|
+
# @return [Integer] last modification time for this file
|
80
79
|
def mtime
|
81
80
|
modified_time.to_i
|
82
81
|
end
|
83
82
|
|
84
83
|
# Is source path modified?
|
85
84
|
#
|
86
|
-
#
|
85
|
+
# @return [Boolean] true if modified since last write
|
87
86
|
def modified?
|
88
87
|
self.class.mtimes[path] != mtime
|
89
88
|
end
|
90
89
|
|
91
90
|
# Whether to write the file to the filesystem
|
92
91
|
#
|
93
|
-
#
|
94
|
-
# bridgetown.config.yml contain `published: false`.
|
92
|
+
# @return [Boolean] true unless the defaults for the destination path contain `published: false`
|
95
93
|
def write?
|
96
94
|
publishable = defaults.fetch("published", true)
|
97
95
|
return publishable unless @collection
|
@@ -99,11 +97,10 @@ module Bridgetown
|
|
99
97
|
publishable && @collection.write?
|
100
98
|
end
|
101
99
|
|
102
|
-
# Write the static file to the destination directory (if modified)
|
103
|
-
#
|
104
|
-
# dest - The String path to the destination dir.
|
100
|
+
# Write the static file to the destination directory (if modified)
|
105
101
|
#
|
106
|
-
#
|
102
|
+
# @param dest [String] path to the destination dir
|
103
|
+
# @return [Boolean] false if the file was not modified since last time (no-op)
|
107
104
|
def write(dest)
|
108
105
|
dest_path = destination(dest)
|
109
106
|
return false if File.exist?(dest_path) && !modified?
|
@@ -152,12 +149,12 @@ module Bridgetown
|
|
152
149
|
#
|
153
150
|
# NOTE: `String#gsub!` removes all trailing periods (in comparison to `String#chomp!`)
|
154
151
|
#
|
155
|
-
#
|
152
|
+
# @example
|
156
153
|
# When `relative_path` is "_methods/site/my-cool-avatar...png":
|
157
154
|
# cleaned_relative_path
|
158
155
|
# # => "/site/my-cool-avatar"
|
159
156
|
#
|
160
|
-
#
|
157
|
+
# @return [String] cleaned relative path of the static file
|
161
158
|
def cleaned_relative_path
|
162
159
|
@cleaned_relative_path ||= begin
|
163
160
|
cleaned = relative_path[0..-extname.length - 1]
|
@@ -169,7 +166,7 @@ module Bridgetown
|
|
169
166
|
|
170
167
|
# Applies a similar URL-building technique as resources that takes
|
171
168
|
# the collection's URL template into account. The default URL template can
|
172
|
-
# be overriden in the collection's configuration
|
169
|
+
# be overriden in the collection's configuration
|
173
170
|
def url
|
174
171
|
@url ||= begin
|
175
172
|
newly_processed = false
|
@@ -183,19 +180,17 @@ module Bridgetown
|
|
183
180
|
end
|
184
181
|
end
|
185
182
|
|
186
|
-
#
|
183
|
+
# @return [Symbol, nil] type of the collection if present
|
187
184
|
def type
|
188
185
|
@type ||= @collection&.label&.to_sym
|
189
186
|
end
|
190
187
|
|
191
|
-
#
|
192
|
-
# as defined in bridgetown.config.yml.
|
188
|
+
# @return [Hash] front matter defaults defined for the file's URL and/or type
|
193
189
|
def defaults
|
194
190
|
@defaults ||= site.frontmatter_defaults.all url, type
|
195
191
|
end
|
196
192
|
|
197
|
-
#
|
198
|
-
# Includes only the relative path of the object.
|
193
|
+
# @return [String] includes only the relative path of the object
|
199
194
|
def inspect
|
200
195
|
"#<#{self.class} @relative_path=#{relative_path.inspect}>"
|
201
196
|
end
|
@@ -23,7 +23,7 @@ module Bridgetown
|
|
23
23
|
class ClassMap < Liquid::Tag
|
24
24
|
# @see https://api.rubyonrails.org/classes/ActiveModel/Type/Boolean.html
|
25
25
|
FALSE_VALUES = [
|
26
|
-
nil, "nil", "NIL",
|
26
|
+
nil, "nil", "NIL", 0, "0", :"0", "f", :f, "F", :F, "false",
|
27
27
|
false, "FALSE", :FALSE,
|
28
28
|
].to_set.freeze
|
29
29
|
|
@@ -12,7 +12,7 @@ module Bridgetown
|
|
12
12
|
|
13
13
|
all, @path, @date, @slug = *name.sub(%r!^/!, "").match(MATCHER)
|
14
14
|
unless all
|
15
|
-
raise Bridgetown::Errors::
|
15
|
+
raise Bridgetown::Errors::FatalException,
|
16
16
|
"'#{name}' does not contain valid date and/or title."
|
17
17
|
end
|
18
18
|
|
@@ -31,24 +31,6 @@ module Bridgetown
|
|
31
31
|
def ==(other)
|
32
32
|
other.relative_path.to_s.match(@name_regex)
|
33
33
|
end
|
34
|
-
|
35
|
-
def deprecated_equality(other)
|
36
|
-
slug == post_slug(other) &&
|
37
|
-
post_date.year == other.date.year &&
|
38
|
-
post_date.month == other.date.month &&
|
39
|
-
post_date.day == other.date.day
|
40
|
-
end
|
41
|
-
|
42
|
-
private
|
43
|
-
|
44
|
-
# Construct the directory-aware post slug for a Bridgetown::Post
|
45
|
-
#
|
46
|
-
# other - the Bridgetown::Post
|
47
|
-
#
|
48
|
-
# Returns the post slug with the subdirectory (relative to _posts)
|
49
|
-
def post_slug(other)
|
50
|
-
other.data.slug
|
51
|
-
end
|
52
34
|
end
|
53
35
|
|
54
36
|
class PostUrl < Liquid::Tag
|
@@ -75,19 +57,7 @@ module Bridgetown
|
|
75
57
|
site.collections.posts.resources.each do |document|
|
76
58
|
return relative_url(document) if @post == document
|
77
59
|
|
78
|
-
|
79
|
-
# with deprecation warning if this matches
|
80
|
-
next unless @post.deprecated_equality document
|
81
|
-
|
82
|
-
Bridgetown::Deprecator.deprecation_message(
|
83
|
-
"A call to " \
|
84
|
-
"'{% post_url #{@post.name} %}' did not match " \
|
85
|
-
"a post using the new matching method of checking name " \
|
86
|
-
"(path-date-slug) equality. Please make sure that you " \
|
87
|
-
"change this tag to match the post's name exactly."
|
88
|
-
)
|
89
|
-
|
90
|
-
return relative_url(document)
|
60
|
+
next
|
91
61
|
end
|
92
62
|
|
93
63
|
raise Bridgetown::Errors::PostURLError, <<~MSG
|
@@ -4,9 +4,9 @@ Bridgetown.initializer :dotenv do |config|
|
|
4
4
|
Bridgetown.load_dotenv root: config.root_dir
|
5
5
|
end
|
6
6
|
|
7
|
-
Bridgetown.initializer :ssr do |config, setup: nil|
|
7
|
+
Bridgetown.initializer :ssr do |config, setup: nil, **options|
|
8
8
|
config.roda do |app|
|
9
|
-
app.plugin(:bridgetown_ssr, &setup)
|
9
|
+
app.plugin(:bridgetown_ssr, options, &setup)
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
@@ -4,13 +4,11 @@ module Bridgetown
|
|
4
4
|
module Utils
|
5
5
|
module RequireGems
|
6
6
|
class << self
|
7
|
-
#
|
8
7
|
# Require a gem or gems. If it's not present, show a very nice error
|
9
8
|
# message that explains everything and is much more helpful than the
|
10
9
|
# normal LoadError.
|
11
10
|
#
|
12
|
-
# names
|
13
|
-
#
|
11
|
+
# @param names [String, Array<String>] gem name or array of gem names
|
14
12
|
def require_with_graceful_fail(names)
|
15
13
|
Array(names).each do |name|
|
16
14
|
Bridgetown.logger.debug "Requiring:", name.to_s
|