bridgetown-core 1.3.4 → 2.0.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (140) hide show
  1. checksums.yaml +4 -4
  2. data/bin/bridgetown +0 -6
  3. data/bin/bt +6 -0
  4. data/bridgetown-core.gemspec +9 -6
  5. data/lib/bridgetown-core/cleaner.rb +1 -1
  6. data/lib/bridgetown-core/collection.rb +30 -18
  7. data/lib/bridgetown-core/commands/build.rb +9 -22
  8. data/lib/bridgetown-core/commands/concerns/actions.rb +15 -8
  9. data/lib/bridgetown-core/commands/concerns/configuration_overridable.rb +1 -1
  10. data/lib/bridgetown-core/commands/console.rb +3 -0
  11. data/lib/bridgetown-core/commands/doctor.rb +2 -4
  12. data/lib/bridgetown-core/commands/esbuild/esbuild.defaults.js.erb +1 -1
  13. data/lib/bridgetown-core/commands/esbuild/migrate-from-webpack.rb +1 -1
  14. data/lib/bridgetown-core/commands/esbuild/update.rb +2 -2
  15. data/lib/bridgetown-core/commands/esbuild.rb +3 -3
  16. data/lib/bridgetown-core/commands/new.rb +32 -39
  17. data/lib/bridgetown-core/commands/start.rb +76 -60
  18. data/lib/bridgetown-core/component.rb +19 -13
  19. data/lib/bridgetown-core/concerns/layout_placeable.rb +1 -1
  20. data/lib/bridgetown-core/concerns/prioritizable.rb +11 -1
  21. data/lib/bridgetown-core/concerns/site/configurable.rb +7 -18
  22. data/lib/bridgetown-core/concerns/site/content.rb +10 -9
  23. data/lib/bridgetown-core/concerns/site/extensible.rb +4 -6
  24. data/lib/bridgetown-core/concerns/site/fast_refreshable.rb +161 -0
  25. data/lib/bridgetown-core/concerns/site/processable.rb +1 -0
  26. data/lib/bridgetown-core/concerns/site/renderable.rb +31 -7
  27. data/lib/bridgetown-core/concerns/site/ssr.rb +23 -9
  28. data/lib/bridgetown-core/concerns/site/writable.rb +1 -1
  29. data/lib/bridgetown-core/concerns/transformable.rb +3 -5
  30. data/lib/bridgetown-core/configuration/configuration_dsl.rb +23 -14
  31. data/lib/bridgetown-core/configuration.rb +67 -114
  32. data/lib/bridgetown-core/configurations/bt-postcss.rb +1 -2
  33. data/lib/bridgetown-core/configurations/cypress/cypress_tasks +2 -2
  34. data/lib/bridgetown-core/configurations/cypress.rb +1 -1
  35. data/lib/bridgetown-core/configurations/gh-pages/gh-pages.yml +3 -3
  36. data/lib/bridgetown-core/configurations/is-land.rb +1 -1
  37. data/lib/bridgetown-core/configurations/lit.rb +1 -1
  38. data/lib/bridgetown-core/configurations/open-props.rb +1 -1
  39. data/lib/bridgetown-core/configurations/purgecss.rb +1 -1
  40. data/lib/bridgetown-core/configurations/ruby2js.rb +1 -1
  41. data/lib/bridgetown-core/configurations/shoelace.rb +8 -20
  42. data/lib/bridgetown-core/configurations/stimulus.rb +17 -36
  43. data/lib/bridgetown-core/configurations/turbo.rb +1 -2
  44. data/lib/bridgetown-core/converter.rb +38 -10
  45. data/lib/bridgetown-core/converters/erb_templates.rb +9 -26
  46. data/lib/bridgetown-core/converters/identity.rb +1 -1
  47. data/lib/bridgetown-core/converters/liquid_templates.rb +2 -20
  48. data/lib/bridgetown-core/converters/ruby_templates.rb +61 -3
  49. data/lib/bridgetown-core/converters/serbea_templates.rb +12 -24
  50. data/lib/bridgetown-core/current.rb +19 -17
  51. data/lib/bridgetown-core/drops/collection_drop.rb +1 -1
  52. data/lib/bridgetown-core/drops/drop.rb +3 -3
  53. data/lib/bridgetown-core/drops/relations_drop.rb +3 -2
  54. data/lib/bridgetown-core/drops/site_drop.rb +0 -5
  55. data/lib/bridgetown-core/entry_filter.rb +4 -6
  56. data/lib/bridgetown-core/errors.rb +2 -2
  57. data/lib/bridgetown-core/filters/from_liquid.rb +6 -10
  58. data/lib/bridgetown-core/filters/localization_filters.rb +1 -1
  59. data/lib/bridgetown-core/filters/translation_filters.rb +2 -2
  60. data/lib/bridgetown-core/filters.rb +3 -3
  61. data/lib/bridgetown-core/front_matter/defaults.rb +225 -0
  62. data/lib/bridgetown-core/front_matter/importer.rb +34 -0
  63. data/lib/bridgetown-core/front_matter/loaders/base.rb +29 -0
  64. data/lib/bridgetown-core/front_matter/loaders/ruby.rb +113 -0
  65. data/lib/bridgetown-core/front_matter/loaders/yaml.rb +42 -0
  66. data/lib/bridgetown-core/front_matter/loaders.rb +44 -0
  67. data/lib/bridgetown-core/{utils/ruby_front_matter.rb → front_matter/ruby.rb} +5 -5
  68. data/lib/bridgetown-core/front_matter.rb +11 -0
  69. data/lib/bridgetown-core/generated_page.rb +71 -31
  70. data/lib/bridgetown-core/generators/prototype_generator.rb +30 -18
  71. data/lib/bridgetown-core/helpers.rb +36 -47
  72. data/lib/bridgetown-core/hooks.rb +5 -5
  73. data/lib/bridgetown-core/inflector.rb +40 -0
  74. data/lib/bridgetown-core/kramdown/parser/gfm.rb +2 -2
  75. data/lib/bridgetown-core/layout.rb +3 -3
  76. data/lib/bridgetown-core/log_adapter.rb +12 -13
  77. data/lib/bridgetown-core/log_writer.rb +4 -4
  78. data/lib/bridgetown-core/model/base.rb +17 -17
  79. data/lib/bridgetown-core/model/builder_origin.rb +5 -3
  80. data/lib/bridgetown-core/model/origin.rb +1 -3
  81. data/lib/bridgetown-core/model/repo_origin.rb +12 -14
  82. data/lib/bridgetown-core/plugin.rb +0 -1
  83. data/lib/bridgetown-core/plugin_manager.rb +27 -84
  84. data/lib/bridgetown-core/rack/boot.rb +0 -15
  85. data/lib/bridgetown-core/rack/routes.rb +30 -90
  86. data/lib/bridgetown-core/reader.rb +6 -4
  87. data/lib/bridgetown-core/readers/layout_reader.rb +2 -2
  88. data/lib/bridgetown-core/readers/plugin_content_reader.rb +2 -2
  89. data/lib/bridgetown-core/resource/base.rb +112 -29
  90. data/lib/bridgetown-core/resource/destination.rb +1 -1
  91. data/lib/bridgetown-core/resource/relations.rb +11 -8
  92. data/lib/bridgetown-core/resource/taxonomy_type.rb +3 -1
  93. data/lib/bridgetown-core/resource/transformer.rb +4 -4
  94. data/lib/bridgetown-core/ruby_template_view.rb +44 -28
  95. data/lib/bridgetown-core/signals.rb +95 -0
  96. data/lib/bridgetown-core/site.rb +22 -4
  97. data/lib/bridgetown-core/slot.rb +5 -5
  98. data/lib/bridgetown-core/static_file.rb +5 -7
  99. data/lib/bridgetown-core/tags/asset_path.rb +11 -2
  100. data/lib/bridgetown-core/tags/find.rb +3 -5
  101. data/lib/bridgetown-core/tags/highlight.rb +3 -3
  102. data/lib/bridgetown-core/tags/post_url.rb +1 -1
  103. data/lib/bridgetown-core/tasks/bridgetown_tasks.rake +2 -2
  104. data/lib/bridgetown-core/utils/aux.rb +41 -41
  105. data/lib/bridgetown-core/utils/loaders_manager.rb +2 -21
  106. data/lib/bridgetown-core/utils/ruby_exec.rb +17 -0
  107. data/lib/bridgetown-core/utils.rb +46 -110
  108. data/lib/bridgetown-core/version.rb +2 -2
  109. data/lib/bridgetown-core/watcher.rb +21 -10
  110. data/lib/bridgetown-core.rb +35 -49
  111. data/lib/roda/plugins/bridgetown_server.rb +54 -12
  112. data/lib/roda/plugins/bridgetown_ssr.rb +13 -2
  113. data/lib/roda/plugins/ssg.rb +72 -0
  114. data/lib/site_template/.gitignore +9 -3
  115. data/lib/site_template/Gemfile.erb +3 -3
  116. data/lib/site_template/README.md +3 -4
  117. data/lib/site_template/Rakefile.erb +2 -15
  118. data/lib/site_template/TEMPLATES/erb/_partials/_head.erb +2 -2
  119. data/lib/site_template/TEMPLATES/serbea/_partials/_head.serb +2 -2
  120. data/lib/site_template/config/initializers.rb +60 -22
  121. data/lib/site_template/config/puma.rb +2 -0
  122. data/lib/site_template/package.json.erb +2 -27
  123. data/lib/site_template/src/index.md.erb +3 -3
  124. data/lib/site_template/tmp/pids/.keep +0 -0
  125. metadata +98 -63
  126. data/lib/bridgetown-core/commands/webpack/enable-postcss.rb +0 -12
  127. data/lib/bridgetown-core/commands/webpack/setup.rb +0 -4
  128. data/lib/bridgetown-core/commands/webpack/update.rb +0 -24
  129. data/lib/bridgetown-core/commands/webpack/webpack.config.js +0 -31
  130. data/lib/bridgetown-core/commands/webpack/webpack.defaults.js.erb +0 -135
  131. data/lib/bridgetown-core/commands/webpack.rb +0 -82
  132. data/lib/bridgetown-core/concerns/front_matter_importer.rb +0 -52
  133. data/lib/bridgetown-core/concerns/liquid_renderable.rb +0 -30
  134. data/lib/bridgetown-core/core_ext/psych.rb +0 -15
  135. data/lib/bridgetown-core/drops/url_drop.rb +0 -152
  136. data/lib/bridgetown-core/frontmatter_defaults.rb +0 -223
  137. data/lib/bridgetown-core/rack/static_indexes.rb +0 -31
  138. data/lib/bridgetown-core/url.rb +0 -166
  139. data/lib/bridgetown-core/utils/ansi.rb +0 -57
  140. data/lib/site_template/bridgetown.config.yml +0 -33
@@ -9,7 +9,7 @@ $LOAD_PATH.unshift __dir__ # For use/testing when no gem is installed
9
9
  # Returns nothing.
10
10
  def require_all(path)
11
11
  glob = File.join(__dir__, path, "*.rb")
12
- Dir[glob].sort.each do |f|
12
+ Dir[glob].each do |f|
13
13
  require f
14
14
  end
15
15
  end
@@ -31,35 +31,29 @@ require "csv"
31
31
  require "json"
32
32
  require "yaml"
33
33
 
34
+ # Pull in Foundation gem
35
+ require "bridgetown-foundation"
36
+
34
37
  # 3rd party
35
- require "active_support"
36
- require "active_support/core_ext/class/attribute"
37
- require "active_support/core_ext/hash/keys"
38
- require "active_support/core_ext/module/delegation"
38
+ require "active_support" # TODO: remove by the end of 2024
39
39
  require "active_support/core_ext/object/blank"
40
- require "active_support/core_ext/object/deep_dup"
41
- require "active_support/core_ext/object/inclusion"
42
40
  require "active_support/core_ext/string/inflections"
43
- require "active_support/core_ext/string/inquiry"
44
41
  require "active_support/core_ext/string/output_safety"
45
- require "active_support/core_ext/string/starts_ends_with"
46
- require "active_support/current_attributes"
47
- require "active_support/descendants_tracker"
48
- require "hash_with_dot_access"
49
42
  require "addressable/uri"
50
43
  require "liquid"
51
44
  require "listen"
52
45
  require "kramdown"
53
- require "colorator"
54
46
  require "i18n"
55
47
  require "i18n/backend/fallbacks"
56
48
  require "faraday"
49
+ require "signalize"
57
50
  require "thor"
58
- require "zeitwerk"
59
51
 
60
52
  # Ensure we can set up fallbacks so the default locale gets used
61
53
  I18n::Backend::Simple.include I18n::Backend::Fallbacks
62
54
 
55
+ # Monkey patches:
56
+
63
57
  module HashWithDotAccess
64
58
  class Hash # :nodoc:
65
59
  def to_liquid
@@ -72,6 +66,8 @@ end
72
66
  class Rb < String; end
73
67
 
74
68
  module Bridgetown
69
+ using Bridgetown::Refinements
70
+
75
71
  autoload :Cache, "bridgetown-core/cache"
76
72
  autoload :Current, "bridgetown-core/current"
77
73
  autoload :Cleaner, "bridgetown-core/cleaner"
@@ -82,14 +78,13 @@ module Bridgetown
82
78
  autoload :EntryFilter, "bridgetown-core/entry_filter"
83
79
  # TODO: we have too many errors! This is silly
84
80
  autoload :Errors, "bridgetown-core/errors"
85
- autoload :FrontmatterDefaults, "bridgetown-core/frontmatter_defaults"
86
- autoload :FrontMatterImporter, "bridgetown-core/concerns/front_matter_importer"
81
+ autoload :FrontMatter, "bridgetown-core/front_matter"
87
82
  autoload :GeneratedPage, "bridgetown-core/generated_page"
88
83
  autoload :Hooks, "bridgetown-core/hooks"
84
+ autoload :Inflector, "bridgetown-core/inflector"
89
85
  autoload :Layout, "bridgetown-core/layout"
90
86
  autoload :LayoutPlaceable, "bridgetown-core/concerns/layout_placeable"
91
87
  autoload :LayoutReader, "bridgetown-core/readers/layout_reader"
92
- autoload :LiquidRenderable, "bridgetown-core/concerns/liquid_renderable"
93
88
  autoload :Localizable, "bridgetown-core/concerns/localizable"
94
89
  autoload :LiquidRenderer, "bridgetown-core/liquid_renderer"
95
90
  autoload :LogAdapter, "bridgetown-core/log_adapter"
@@ -100,11 +95,11 @@ module Bridgetown
100
95
  autoload :Reader, "bridgetown-core/reader"
101
96
  autoload :RubyTemplateView, "bridgetown-core/ruby_template_view"
102
97
  autoload :LogWriter, "bridgetown-core/log_writer"
98
+ autoload :Signals, "bridgetown-core/signals"
103
99
  autoload :Site, "bridgetown-core/site"
104
100
  autoload :Slot, "bridgetown-core/slot"
105
101
  autoload :StaticFile, "bridgetown-core/static_file"
106
102
  autoload :Transformable, "bridgetown-core/concerns/transformable"
107
- autoload :URL, "bridgetown-core/url"
108
103
  autoload :Utils, "bridgetown-core/utils"
109
104
  autoload :VERSION, "bridgetown-core/version"
110
105
  autoload :Watcher, "bridgetown-core/watcher"
@@ -126,13 +121,12 @@ module Bridgetown
126
121
  require_all "bridgetown-core/drops"
127
122
  require_all "bridgetown-core/generators"
128
123
  require_all "bridgetown-core/tags"
129
- require_all "bridgetown-core/core_ext"
130
124
 
131
125
  class << self
132
126
  # Tells you which Bridgetown environment you are building in so
133
127
  # you can skip tasks if you need to.
134
128
  def environment
135
- (ENV["BRIDGETOWN_ENV"] || "development").inquiry
129
+ (ENV["BRIDGETOWN_ENV"] || "development").questionable
136
130
  end
137
131
  alias_method :env, :environment
138
132
 
@@ -246,21 +240,21 @@ module Bridgetown
246
240
  Bridgetown::Current.preloaded_configuration.initializers[name.to_sym] =
247
241
  Bridgetown::Configuration::Initializer.new(
248
242
  name: name.to_sym,
249
- block: block,
243
+ block:,
250
244
  completed: false
251
245
  )
252
246
  end
253
247
 
254
248
  # @yieldself [Bridgetown::Configuration::ConfigurationDSL]
255
- def configure(&block)
256
- initializer :init, &block
249
+ def configure(&)
250
+ initializer(:init, &)
257
251
  end
258
252
 
259
253
  # Convenience method to register a new Thor command
260
254
  #
261
255
  # @see Bridgetown::Commands::Registrations.register
262
- def register_command(&block)
263
- Bridgetown::Commands::Registrations.register(&block)
256
+ def register_command(&)
257
+ Bridgetown::Commands::Registrations.register(&)
264
258
  end
265
259
 
266
260
  def load_tasks
@@ -268,7 +262,7 @@ module Bridgetown
268
262
  unless Bridgetown::Current.preloaded_configuration
269
263
  Bridgetown::Current.preloaded_configuration = Bridgetown::Configuration::Preflight.new
270
264
  end
271
- Bridgetown::PluginManager.setup_bundler(skip_yarn: true)
265
+ Bridgetown::PluginManager.setup_bundler
272
266
 
273
267
  if Bridgetown::Current.preloaded_configuration.is_a?(Bridgetown::Configuration::Preflight)
274
268
  Bridgetown::Current.preloaded_configuration = Bridgetown.configuration
@@ -293,11 +287,11 @@ module Bridgetown
293
287
  # the block on to it.
294
288
  #
295
289
  # @return [void]
296
- def with_unbundled_env(&block)
290
+ def with_unbundled_env(&)
297
291
  if Bundler.bundler_major_version >= 2
298
- Bundler.method(:with_unbundled_env).call(&block)
292
+ Bundler.method(:with_unbundled_env).call(&)
299
293
  else
300
- Bundler.method(:with_clean_env).call(&block)
294
+ Bundler.method(:with_clean_env).call(&)
301
295
  end
302
296
  end
303
297
 
@@ -337,17 +331,6 @@ module Bridgetown
337
331
  @logger = LogAdapter.new(writer, (ENV["BRIDGETOWN_LOG_LEVEL"] || :info).to_sym)
338
332
  end
339
333
 
340
- # Deprecated. Now using the Current site.
341
- #
342
- # @return [Array<Bridgetown::Site>] the Bridgetown sites created.
343
- def sites
344
- Deprecator.deprecation_message(
345
- "Bridgetown.sites will be removed in the next version. Use Bridgetown::Current.sites" \
346
- "instead"
347
- )
348
- [Bridgetown::Current.site].compact
349
- end
350
-
351
334
  # Ensures the questionable path is prefixed with the base directory
352
335
  # and prepends the questionable path with the base directory if false.
353
336
  #
@@ -390,9 +373,7 @@ module Bridgetown
390
373
  )
391
374
  end
392
375
  end
393
- end
394
376
 
395
- module Bridgetown
396
377
  module Model; end
397
378
 
398
379
  module Resource
@@ -405,13 +386,18 @@ module Bridgetown
405
386
  end
406
387
  end
407
388
  end
408
- end
409
389
 
410
- # This method is available in Ruby 3, monkey patching for older versions
411
- Psych.extend Bridgetown::CoreExt::Psych::SafeLoadFile unless Psych.respond_to?(:safe_load_file)
390
+ # mixin for identity so Roda knows to call renderable objects
391
+ module RodaCallable
392
+ def self.===(other)
393
+ other.class < self
394
+ end
395
+ end
396
+ end
412
397
 
413
- loader = Zeitwerk::Loader.new
414
- loader.push_dir File.join(__dir__, "bridgetown-core/model"), namespace: Bridgetown::Model
415
- loader.push_dir File.join(__dir__, "bridgetown-core/resource"), namespace: Bridgetown::Resource
416
- loader.setup # ready!
398
+ Zeitwerk.with_loader do |l|
399
+ l.push_dir File.join(__dir__, "bridgetown-core/model"), namespace: Bridgetown::Model
400
+ l.push_dir File.join(__dir__, "bridgetown-core/resource"), namespace: Bridgetown::Resource
401
+ l.setup # ready!
402
+ end
417
403
  Bridgetown::Model::Origin # this needs to load first
@@ -11,6 +11,7 @@ class Roda
11
11
  "plugin"
12
12
  end
13
13
 
14
+ app.extend ClassMethods # we need to do this here because Roda hasn't done it yet
14
15
  app.plugin :initializers
15
16
  app.plugin :method_override
16
17
  app.plugin :all_verbs
@@ -19,9 +20,8 @@ class Roda
19
20
  app.plugin :json
20
21
  app.plugin :json_parser
21
22
  app.plugin :indifferent_params
22
- app.plugin :cookies
23
- app.plugin :streaming
24
- app.plugin :public, root: Bridgetown::Current.preloaded_configuration.destination
23
+ app.plugin :cookies, path: "/"
24
+ app.plugin :ssg, root: Bridgetown::Current.preloaded_configuration.destination
25
25
  app.plugin :not_found do
26
26
  output_folder = Bridgetown::Current.preloaded_configuration.destination
27
27
  File.read(File.join(output_folder, "404.html"))
@@ -41,6 +41,7 @@ class Roda
41
41
  "500 Internal Server Error"
42
42
  end
43
43
 
44
+ # TODO: there may be a better way to do this, see `exception_page_css` instance method
44
45
  ExceptionPage.class_eval do # rubocop:disable Metrics/BlockLength
45
46
  def self.css
46
47
  <<~CSS
@@ -97,8 +98,16 @@ class Roda
97
98
  CSS
98
99
  end
99
100
  end
101
+ end
102
+
103
+ module ClassMethods
104
+ def root_hook(&block)
105
+ opts[:root_hook] = block
106
+ end
107
+ end
100
108
 
101
- app.before do
109
+ module InstanceMethods
110
+ def initialize_bridgetown_context
102
111
  if self.class.opts[:bridgetown_site]
103
112
  # The site had previously been initialized via the bridgetown_ssr plugin
104
113
  Bridgetown::Current.sites[self.class.opts[:bridgetown_site].label] =
@@ -107,30 +116,63 @@ class Roda
107
116
  end
108
117
  Bridgetown::Current.preloaded_configuration ||=
109
118
  self.class.opts[:bridgetown_preloaded_config]
119
+ end
110
120
 
121
+ def initialize_bridgetown_root # rubocop:todo Metrics/AbcSize
111
122
  request.root do
112
- output_folder = Bridgetown::Current.preloaded_configuration.destination
113
- File.read(File.join(output_folder, "index.html"))
114
- rescue StandardError
123
+ hook_result = instance_exec(&self.class.opts[:root_hook]) if self.class.opts[:root_hook]
124
+ next hook_result if hook_result
125
+
126
+ status, headers, body = self.class.opts[:ssg_server].serving(
127
+ request, File.join(self.class.opts[:ssg_root], "index.html")
128
+ )
129
+ response_headers = response.headers
130
+ response_headers.replace(headers)
131
+
132
+ request.halt [status, response_headers, body]
133
+ rescue StandardError => e
134
+ Bridgetown.logger.debug("Root handler error: #{e.message}")
115
135
  response.status = 500
116
136
  "<p>ERROR: cannot find <code>index.html</code> in the output folder.</p>"
117
137
  end
118
138
  end
139
+
140
+ # This is useful if you're passing the Roda app instance around and want to
141
+ # get at `request` / `response` easily as local variables
142
+ def deconstruct_keys(*)
143
+ { request:, response: }
144
+ end
119
145
  end
120
146
 
121
147
  Roda::RodaRequest.alias_method :_previous_roda_cookies, :cookies
122
148
 
123
149
  module RequestMethods
124
150
  # Monkeypatch Roda/Rack's Request object so it returns a hash which allows for
125
- # indifferent access
151
+ # symbol or dot access
126
152
  def cookies
127
- # TODO: maybe replace with a simpler hash that offers an overloaded `[]` method
128
- _previous_roda_cookies.with_indifferent_access
153
+ HashWithDotAccess::Hash.new(_previous_roda_cookies)
129
154
  end
130
155
 
131
- # Starts up the Bridgetown routing system
156
+ # Start up the Bridgetown routing system
132
157
  def bridgetown
133
- Bridgetown::Rack::Routes.start!(scope)
158
+ scope.initialize_bridgetown_context
159
+ scope.initialize_bridgetown_root
160
+
161
+ # Run the static file server
162
+ ssg
163
+
164
+ # There are two different code paths depending on if there's a site `base_path` configured
165
+ if Bridgetown::Current.preloaded_configuration.base_path == "/"
166
+ Bridgetown::Rack::Routes.load_all scope
167
+ return
168
+ end
169
+
170
+ # Support custom base_path configurations
171
+ on(Bridgetown::Current.preloaded_configuration.base_path.delete_prefix("/")) do
172
+ Bridgetown::Rack::Routes.load_all scope
173
+ end
174
+
175
+ nil
134
176
  end
135
177
  end
136
178
  end
@@ -9,12 +9,23 @@ class Roda
9
9
  def bridgetown_site
10
10
  self.class.opts[:bridgetown_site]
11
11
  end
12
+
13
+ alias_method :site, :bridgetown_site
14
+ end
15
+
16
+ def self.load_dependencies(app)
17
+ app.plugin :custom_block_results
18
+
19
+ # This lets us return callable objects directly in Roda response blocks
20
+ app.handle_block_result(Bridgetown::RodaCallable) do |callable|
21
+ callable.(self)
22
+ end
12
23
  end
13
24
 
14
- def self.configure(app, _opts = {}, &block)
25
+ def self.configure(app, _opts = {}, &)
15
26
  app.include Bridgetown::Filters::URLFilters
16
27
  app.opts[:bridgetown_site] =
17
- Bridgetown::Site.start_ssr!(loaders_manager: Bridgetown::Rack.loaders_manager, &block)
28
+ Bridgetown::Site.start_ssr!(loaders_manager: Bridgetown::Rack.loaders_manager, &)
18
29
  end
19
30
  end
20
31
 
@@ -0,0 +1,72 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "uri"
4
+ require "rack/files"
5
+
6
+ class Roda
7
+ module RodaPlugins
8
+ # This is a simplifed and modified variant of Roda's Public core plugin. It adds additional
9
+ # functionality so that you can host an entire static site through Roda. What's necessary for
10
+ # this to work is handling "pretty" URLs, aka:
11
+ #
12
+ # /path/to/page -> /path/to/page.html or /path/to/page/index.html
13
+ # /path/to/page/ -> /path/to/page/index.html
14
+ #
15
+ # It does not support serving compressed files, as that should ideally be handled through a
16
+ # proxy or CDN layer in your architecture.
17
+ module SSG
18
+ PARSER = URI::DEFAULT_PARSER
19
+
20
+ def self.configure(app, opts = {})
21
+ app.opts[:ssg_root] = app.expand_path(opts.fetch(:root, "public"))
22
+ app.opts[:ssg_server] = Rack::Files.new(app.opts[:ssg_root])
23
+ end
24
+
25
+ module RequestMethods
26
+ def ssg
27
+ return unless is_get?
28
+
29
+ path = PARSER.unescape(real_remaining_path)
30
+ return if path.include?("\0")
31
+
32
+ server = roda_class.opts[:ssg_server]
33
+ path = File.join(server.root, *segments_for_path(path))
34
+
35
+ return unless File.file?(path)
36
+
37
+ status, headers, body = server.serving(self, path)
38
+ response_headers = response.headers
39
+ response_headers.replace(headers)
40
+ halt [status, response_headers, body]
41
+ end
42
+
43
+ # TODO: this could be refactored a bit
44
+ def segments_for_path(path) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
45
+ segments = []
46
+
47
+ path.split("/").each do |seg|
48
+ next if seg.empty? || seg == "."
49
+
50
+ seg == ".." ? segments.pop : segments << seg
51
+ end
52
+
53
+ path = File.join(roda_class.opts[:ssg_root], *segments)
54
+ unless File.file?(path)
55
+ path = File.join(path, "index.html")
56
+ if File.file?(path)
57
+ segments << "index.html"
58
+ else
59
+ segments[segments.size - 1] = "#{segments.last}.html"
60
+ end
61
+ end
62
+
63
+ segments
64
+ rescue IndexError
65
+ nil
66
+ end
67
+ end
68
+ end
69
+
70
+ register_plugin :ssg, SSG
71
+ end
72
+ end
@@ -2,13 +2,10 @@
2
2
  output
3
3
  .bridgetown-cache
4
4
  .bridgetown-metadata
5
- .bridgetown-webpack
6
5
  .routes.json
7
6
 
8
7
  # Dependency folders
9
8
  node_modules
10
- bower_components
11
- vendor
12
9
 
13
10
  # Caches
14
11
  .sass-cache
@@ -34,3 +31,12 @@ yarn-debug.log*
34
31
  .pnp.js
35
32
  # Yarn Integrity file
36
33
  .yarn-integrity
34
+
35
+ # Ignore all tempfiles.
36
+ /tmp/*
37
+ !/tmp/.keep
38
+
39
+ # Ignore pidfiles, but keep the directory.
40
+ /tmp/pids/*
41
+ !/tmp/pids/
42
+ !/tmp/pids/.keep
@@ -6,9 +6,9 @@ git_source(:github) { |repo| "https://github.com/#{repo}.git" }
6
6
  #
7
7
  # To install a plugin, run:
8
8
  #
9
- # bundle add new-plugin-name -g bridgetown_plugins
9
+ # bundle add new-plugin-name
10
10
  #
11
- # This will ensure the plugin is added to the correct Bundler group.
11
+ # and add a relevant init comment to your config/initializers.rb file.
12
12
  #
13
13
  # When you run Bridgetown commands, we recommend using a binstub like so:
14
14
  #
@@ -33,4 +33,4 @@ gem "puma", "< 7"
33
33
  # gem "nokogiri", "~> 1.13"
34
34
 
35
35
  # Or for faster parsing of HTML-only resources via Inspectors, use Nokolexbor:
36
- # gem "nokolexbor", "~> 0.4"
36
+ # gem "nokolexbor", "~> 0.5"
@@ -16,18 +16,17 @@ Welcome to your new Bridgetown website! You can update this README file to provi
16
16
  - [GCC](https://gcc.gnu.org/install/)
17
17
  - [Make](https://www.gnu.org/software/make/)
18
18
  - [Ruby](https://www.ruby-lang.org/en/downloads/)
19
- - `>= 2.7`
19
+ - `>= 3.1`
20
20
  - [Bridgetown Gem](https://rubygems.org/gems/bridgetown)
21
21
  - `gem install bridgetown -N`
22
22
  - [Node](https://nodejs.org)
23
- - `>= 12`
24
- - [Yarn](https://yarnpkg.com)
23
+ - `>= 20`
25
24
 
26
25
  ## Install
27
26
 
28
27
  ```sh
29
28
  cd bridgetown-site-folder
30
- bundle install && yarn install
29
+ bundle install && npm install
31
30
  ```
32
31
  > Learn more: [Bridgetown Getting Started Documentation](https://www.bridgetownrb.com/docs/).
33
32
 
@@ -28,25 +28,12 @@ end
28
28
  namespace :frontend do
29
29
  desc "Build the frontend with esbuild for deployment"
30
30
  task :build do
31
- sh "yarn run esbuild"
31
+ sh "npm run esbuild"
32
32
  end
33
33
 
34
34
  desc "Watch the frontend with esbuild during development"
35
35
  task :dev do
36
- sh "yarn run esbuild-dev"
37
- rescue Interrupt
38
- end
39
- end
40
- <%- else -%>
41
- namespace :frontend do
42
- desc "Build the frontend with Webpack for deployment"
43
- task :build do
44
- sh "yarn run webpack-build"
45
- end
46
-
47
- desc "Watch the frontend with Webpack during development"
48
- task :dev do
49
- sh "yarn run webpack-dev --color"
36
+ sh "npm run esbuild-dev"
50
37
  rescue Interrupt
51
38
  end
52
39
  end
@@ -5,6 +5,6 @@
5
5
 
6
6
  <meta name="description" content="<%= metadata.description %>" />
7
7
 
8
- <link rel="stylesheet" href="<%= webpack_path :css %>" />
9
- <script src="<%= webpack_path :js %>" defer></script>
8
+ <link rel="stylesheet" href="<%= asset_path :css %>" />
9
+ <script src="<%= asset_path :js %>" defer></script>
10
10
  <%= live_reload_dev_js %>
@@ -5,6 +5,6 @@
5
5
 
6
6
  <meta name="description" content="{%= metadata.description %}" />
7
7
 
8
- <link rel="stylesheet" href="{%= webpack_path :css %}" />
9
- <script src="{%= webpack_path :js %}" defer></script>
8
+ <link rel="stylesheet" href="{%= asset_path :css %}" />
9
+ <script src="{%= asset_path :js %}" defer></script>
10
10
  {%= live_reload_dev_js %}
@@ -1,34 +1,61 @@
1
+ # Welcome to Bridgetown!
2
+ #
3
+ # This configuration file is for settings which affect your whole site.
4
+ #
5
+ # For more documentation on using this initializers file, visit:
6
+ # https://www.bridgetownrb.com/docs/configuration/initializers/
7
+ #
8
+ # A list of all available configuration options can be found here:
9
+ # https://www.bridgetownrb.com/docs/configuration/options
10
+ #
11
+ # For technical reasons, this file is *NOT* reloaded automatically when you use
12
+ # `bin/bridgetown start`. If you change this file, please restart the server process.
13
+ #
14
+ # For reloadable site metadata like title, SEO description, social media
15
+ # handles, etc., take a look at `src/_data/site_metadata.yml`
16
+
1
17
  Bridgetown.configure do |config|
2
- # You can configure aspects of your Bridgetown site here instead of using
3
- # `bridgetown.config.yml`. For example:
18
+ # The base hostname & protocol for your site, e.g. https://example.com
19
+ url ""
20
+
21
+ # Available options are `erb` (default), `serbea`, or `liquid`
22
+ template_engine "erb"
23
+
24
+ # Other options you might want to investigate:
25
+
26
+ # See list of timezone values here:
27
+ # https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
4
28
  #
5
- # permalink "simple"
6
29
  # timezone "America/Los_Angeles"
30
+
31
+ # Add collection pagination features to your site. Documentation here:
32
+ # https://www.bridgetownrb.com/docs/content/pagination
7
33
  #
8
- # You can also modify options on the configuration object directly, like so:
9
- #
10
- # config.autoload_paths << "models"
34
+ # pagination do
35
+ # enabled true
36
+ # end
37
+
38
+ # Configure the permalink style for pages and posts. Custom collections can be
39
+ # configured separately under the `collections` key. Documentation here:
40
+ # https://www.bridgetownrb.com/docs/content/permalinks
11
41
  #
42
+ # permalink "simple"
12
43
 
13
- # You can configure the inflector used by Zeitwerk. In v2.0,
14
- # ActiveSupport::Inflector will become the default.
44
+ # Optionally host your site off a path, e.g. /blog. If you set this option,
45
+ # ensure you use the `relative_url` helper for all links and assets in your HTML.
46
+ # If you're using esbuild for frontend assets, edit `esbuild.config.js` to
47
+ # update `publicPath`.
15
48
  #
16
- # config.inflector = ActiveSupport::Inflector
49
+ # base_path "/"
50
+
51
+ # You can also modify options on this configuration object directly, like so:
17
52
  #
18
- # Add new inflection rules using the following format. Inflections
19
- # are locale specific, and you may define rules for as many different
20
- # locales as you wish. All of these examples are active by default:
21
- # ActiveSupport::Inflector.inflections(:en) do |inflect|
22
- # inflect.plural /^(ox)$/i, "\\1en"
23
- # inflect.singular /^(ox)en/i, "\\1"
24
- # inflect.irregular "person", "people"
25
- # inflect.uncountable %w( fish sheep )
26
- # end
53
+ # config.autoload_paths << "models"
54
+
55
+ # If you find you're having trouble using the new Fast Refresh feature in development,
56
+ # you can disable it to force full rebuilds instead:
27
57
  #
28
- # These inflection rules are supported but not enabled by default:
29
- # ActiveSupport::Inflector.inflections(:en) do |inflect|
30
- # inflect.acronym "RESTful"
31
- # end
58
+ # fast_refresh false
32
59
 
33
60
  # You can use `init` to initialize various Bridgetown features or plugin gems.
34
61
  # For example, you can use the Dotenv gem to load environment variables from
@@ -58,6 +85,17 @@ Bridgetown.configure do |config|
58
85
  # end
59
86
  #
60
87
 
88
+ # You can configure the inflector used by Zeitwerk and models. A few acronyms are provided
89
+ # by default like HTML, CSS, and JS, so a file like `html_processor.rb` could be defined by
90
+ # `HTMLProcessor`. You can add more like so:
91
+ #
92
+ # config.inflector.configure do |inflections|
93
+ # inflections.acronym "W3C"
94
+ # end
95
+ #
96
+ # Bridgetown's inflector is based on Dry::Inflector so you can read up on how to add inflection
97
+ # rules here: https://dry-rb.org/gems/dry-inflector/1.0/#custom-inflection-rules
98
+
61
99
  # For more documentation on how to configure your site using this initializers file,
62
100
  # visit: https://edge.bridgetownrb.com/docs/configuration/initializers/
63
101
  end
@@ -19,6 +19,8 @@ max_threads_count = ENV.fetch("BRIDGETOWN_MAX_THREADS") { 5 }
19
19
  min_threads_count = ENV.fetch("BRIDGETOWN_MIN_THREADS") { max_threads_count }
20
20
  threads min_threads_count, max_threads_count
21
21
 
22
+ pidfile ENV["PIDFILE"] || "tmp/pids/server.pid"
23
+
22
24
  # Preload the application for maximum performance
23
25
  #
24
26
  preload_app!