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
@@ -8,15 +8,15 @@ class Bridgetown::Site
8
8
 
9
9
  module ClassMethods
10
10
  # Establish an SSR pipeline for a persistent backend process
11
- def start_ssr!(loaders_manager: nil, &block)
11
+ def start_ssr!(loaders_manager: nil, &)
12
12
  if Bridgetown::Current.site
13
13
  raise Bridgetown::Errors::FatalException, "Bridgetown SSR already started! " \
14
14
  "Check your Rack app for threading issues"
15
15
  end
16
16
 
17
- site = new(Bridgetown::Current.preloaded_configuration, loaders_manager: loaders_manager)
17
+ site = new(Bridgetown::Current.preloaded_configuration, loaders_manager:)
18
18
  site.enable_ssr
19
- site.ssr_setup(&block)
19
+ site.ssr_setup(&)
20
20
 
21
21
  site
22
22
  end
@@ -28,11 +28,24 @@ class Bridgetown::Site
28
28
 
29
29
  def enable_ssr
30
30
  Bridgetown.logger.info "SSR:", "enabled."
31
+ config.fast_refresh = false # SSR mode and Fast Refresh mode are mututally exclusive
31
32
  @ssr_enabled = true
32
33
  end
33
34
 
34
35
  def ssr_setup(&block)
35
- config.serving = true
36
+ Bridgetown::Hooks.trigger :site, :pre_read, self
37
+ ssr_first_read
38
+ Bridgetown::Hooks.trigger :site, :post_read, self
39
+
40
+ block&.call(self) # provide additional setup hook
41
+
42
+ return if Bridgetown.env.production?
43
+
44
+ Bridgetown::Watcher.watch(self, config, &block)
45
+ end
46
+
47
+ def ssr_first_read
48
+ # TODO: this shouldn't be running twice, right?!
36
49
  Bridgetown::Hooks.trigger :site, :pre_read, self
37
50
  defaults_reader.tap do |d|
38
51
  d.path_defaults.clear
@@ -43,12 +56,13 @@ class Bridgetown::Site
43
56
  coll.read
44
57
  self.data = coll.merge_data_resources
45
58
  end
46
- Bridgetown::Hooks.trigger :site, :post_read, self
47
-
48
- block&.call(self) # provide additional setup hook
49
- return if Bridgetown.env.production?
50
59
 
51
- Bridgetown::Watcher.watch(self, config, &block)
60
+ # This part is handled via a hook so it is supported by the SSR "soft reset"
61
+ Bridgetown::Hooks.register_one :site, :post_read, reloadable: false, priority: :high do
62
+ reader.read_directories
63
+ reader.sort_files!
64
+ reader.read_collections
65
+ end
52
66
  end
53
67
 
54
68
  def disable_ssr
@@ -55,7 +55,7 @@ class Bridgetown::Site
55
55
  return
56
56
  end
57
57
 
58
- index_html = <<~HTML
58
+ index_html = <<~HTML # rubocop:disable Bridgetown/InsecureHeredoc
59
59
  <!DOCTYPE html>
60
60
  <html>
61
61
  <head>
@@ -15,11 +15,9 @@ module Bridgetown
15
15
  converters.each_with_index.inject(
16
16
  (alternate_content || document.content).to_s
17
17
  ) do |content, (converter, index)|
18
- output = if converter.method(:convert).arity == 1
19
- converter.convert content
20
- else
21
- converter.convert content, document
22
- end
18
+ output = converter.method(:convert).arity == 1 ?
19
+ converter.convert(content) :
20
+ converter.convert(content, document)
23
21
 
24
22
  yield converter, index, output if block_given?
25
23
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Bridgetown
4
4
  class Configuration
5
- class ConfigurationDSL < Bridgetown::Utils::RubyFrontMatter
5
+ class ConfigurationDSL < Bridgetown::FrontMatter::RubyFrontMatter
6
6
  attr_reader :context
7
7
 
8
8
  # @yieldself [ConfigurationDSL]
@@ -11,7 +11,7 @@ module Bridgetown
11
11
  @scope.initializers[name.to_sym].completed
12
12
 
13
13
  initializer = _setup_initializer(
14
- name: name, require_gem: require_gem, require_initializer: require_initializer
14
+ name:, require_gem:, require_initializer:
15
15
  )
16
16
 
17
17
  return unless initializer.nil? || initializer.completed == false
@@ -27,36 +27,38 @@ module Bridgetown
27
27
  end
28
28
 
29
29
  Bridgetown.logger.debug "Initializing:", name
30
- @scope.initializers[name.to_sym].block.(self, **@scope.init_params[name].symbolize_keys)
30
+ @scope.initializers[name.to_sym].block.(
31
+ self, **@scope.init_params[name].transform_keys(&:to_sym)
32
+ )
31
33
  initializer.completed = true
32
34
  end
33
35
 
34
- def only(*context, &block)
36
+ def only(*context, &)
35
37
  return unless context.any? { _1 == @context }
36
38
 
37
- instance_exec(&block)
39
+ instance_exec(&)
38
40
  end
39
41
 
40
- def except(*context, &block)
42
+ def except(*context, &)
41
43
  return if context.any? { _1 == @context }
42
44
 
43
- instance_exec(&block)
45
+ instance_exec(&)
44
46
  end
45
47
 
46
48
  def hook(
47
49
  owner,
48
50
  event,
49
51
  priority: Bridgetown::Hooks::DEFAULT_PRIORITY,
50
- &block
52
+ &
51
53
  )
52
- Bridgetown::Hooks.register_one(owner, event, priority: priority, reloadable: false, &block)
54
+ Bridgetown::Hooks.register_one(owner, event, priority:, reloadable: false, &)
53
55
  end
54
56
 
55
57
  def source_manifest(**kwargs)
56
58
  @scope.source_manifests << SourceManifest.new(**kwargs)
57
59
  end
58
60
 
59
- def builder(klass = nil, &block)
61
+ def builder(klass = nil, &)
60
62
  return klass.register if klass.is_a?(Class) && klass < Bridgetown::Builder
61
63
 
62
64
  unless klass.is_a?(Symbol)
@@ -64,7 +66,7 @@ module Bridgetown
64
66
  end
65
67
 
66
68
  Object.const_set(
67
- klass, Class.new(Bridgetown::Builder, &block).tap(&:register)
69
+ klass, Class.new(Bridgetown::Builder, &).tap(&:register)
68
70
  )
69
71
  end
70
72
 
@@ -72,8 +74,9 @@ module Bridgetown
72
74
  @scope.roda_initializers << block
73
75
  end
74
76
 
75
- def timezone(tz) # rubocop:disable Naming/MethodParameterName
76
- Bridgetown.set_timezone(tz)
77
+ def timezone(new_timezone)
78
+ @data[:timezone] = new_timezone
79
+ Bridgetown.set_timezone(new_timezone)
77
80
  end
78
81
 
79
82
  def method_missing(key, *value, &block) # rubocop:disable Style/MissingRespondToMissing
@@ -109,7 +112,7 @@ module Bridgetown
109
112
 
110
113
  def reflect(name, require_gem: true, require_initializer: true)
111
114
  initializer = _setup_initializer(
112
- name: name, require_gem: require_gem, require_initializer: require_initializer
115
+ name:, require_gem:, require_initializer:
113
116
  )
114
117
 
115
118
  if initializer.nil?
@@ -145,6 +148,12 @@ module Bridgetown
145
148
  def _in_require_denylist?(name)
146
149
  REQUIRE_DENYLIST.include?(name.to_sym)
147
150
  end
151
+
152
+ # Initializers that are part of the Bridgetown boot sequence. Site owners can override
153
+ # defaults by running any of these manually…init is no-op if the initializer was already run.
154
+ def _run_builtins!
155
+ init :streamlined
156
+ end
148
157
  end
149
158
  end
150
159
  end
@@ -3,6 +3,8 @@
3
3
  module Bridgetown
4
4
  # The primary configuration object for a Bridgetown project
5
5
  class Configuration < HashWithDotAccess::Hash
6
+ using Bridgetown::Refinements
7
+
6
8
  REQUIRE_DENYLIST = %i(parse_routes ssr) # rubocop:disable Style/MutableConstant
7
9
 
8
10
  Initializer = Struct.new(:name, :block, :completed, keyword_init: true) do
@@ -26,69 +28,65 @@ module Bridgetown
26
28
  # Strings rather than symbols are used for compatibility with YAML.
27
29
  DEFAULTS = {
28
30
  # Where things are
29
- "root_dir" => Dir.pwd,
30
- "plugins_dir" => "plugins",
31
- "source" => "src",
32
- "destination" => "output",
33
- "collections_dir" => "",
34
- "cache_dir" => ".bridgetown-cache",
35
- "layouts_dir" => "_layouts",
36
- "components_dir" => "_components",
37
- "islands_dir" => "_islands",
38
- "partials_dir" => "_partials",
39
- "collections" => {},
40
- "taxonomies" => {
31
+ "root_dir" => Dir.pwd,
32
+ "plugins_dir" => "plugins",
33
+ "source" => "src",
34
+ "destination" => "output",
35
+ "collections_dir" => "",
36
+ "cache_dir" => ".bridgetown-cache",
37
+ "layouts_dir" => "_layouts",
38
+ "components_dir" => "_components",
39
+ "islands_dir" => "_islands",
40
+ "partials_dir" => "_partials",
41
+ "collections" => {},
42
+ "taxonomies" => {
41
43
  category: { key: "categories", title: "Category" }, tag: { key: "tags", title: "Tag" },
42
44
  },
43
- "autoload_paths" => [],
44
- "inflector" => nil,
45
- "eager_load_paths" => [],
46
- "autoloader_collapsed_paths" => [],
47
- "additional_watch_paths" => [],
45
+ "autoload_paths" => [],
46
+ "inflector" => Bridgetown::Inflector.new,
47
+ "eager_load_paths" => [],
48
+ "autoloader_collapsed_paths" => [],
49
+ "additional_watch_paths" => [],
50
+ "defaults" => [],
48
51
 
49
52
  # Handling Reading
50
- "include" => [".htaccess", "_redirects", ".well-known"],
51
- "exclude" => [],
52
- "keep_files" => [".git", ".svn", "_bridgetown"],
53
- "encoding" => "utf-8",
54
- "markdown_ext" => "markdown,mkdown,mkdn,mkd,md",
55
- "strict_front_matter" => false,
56
- "slugify_mode" => "pretty",
53
+ "include" => [".htaccess", "_redirects", ".well-known"],
54
+ "exclude" => [],
55
+ "keep_files" => [".git", ".svn", "_bridgetown"],
56
+ "encoding" => "utf-8",
57
+ "markdown_ext" => "markdown,mkdown,mkdn,mkd,md",
58
+ "strict_front_matter" => false,
59
+ "slugify_mode" => "pretty",
57
60
 
58
61
  # Filtering Content
59
- "future" => false,
60
- "unpublished" => false,
61
- "ruby_in_front_matter" => true,
62
+ "future" => false,
63
+ "unpublished" => false,
64
+ "ruby_in_front_matter" => true,
62
65
 
63
66
  # Conversion
64
- "content_engine" => "resource",
65
- "markdown" => "kramdown",
66
- "highlighter" => "rouge",
67
-
68
- # Serving
69
- "port" => "4000",
70
- "host" => "127.0.0.1",
71
- "base_path" => "/",
72
- "show_dir_listing" => false,
67
+ "template_engine" => "erb",
68
+ "markdown" => "kramdown",
69
+ "highlighter" => "rouge",
70
+ "support_data_as_view_methods" => true,
73
71
 
74
72
  # Output Configuration
75
- "available_locales" => [:en],
76
- "default_locale" => :en,
77
- "prefix_default_locale" => false,
78
- "permalink" => nil, # default is set according to content engine
79
- "timezone" => nil, # use the local timezone
73
+ "base_path" => "/",
74
+ "available_locales" => [:en],
75
+ "default_locale" => :en,
76
+ "prefix_default_locale" => false,
77
+ "permalink" => "pretty",
78
+ "timezone" => nil, # use the local timezone
80
79
 
81
- "quiet" => false,
82
- "verbose" => false,
83
- "defaults" => [],
80
+ "quiet" => false,
81
+ "verbose" => false,
84
82
 
85
- "liquid" => {
83
+ "liquid" => {
86
84
  "error_mode" => "warn",
87
85
  "strict_filters" => false,
88
86
  "strict_variables" => false,
89
87
  },
90
88
 
91
- "kramdown" => {
89
+ "kramdown" => {
92
90
  "auto_ids" => true,
93
91
  "toc_levels" => (1..6).to_a,
94
92
  "entity_output" => "as_char",
@@ -101,11 +99,11 @@ module Bridgetown
101
99
  "include_extraction_tags" => false,
102
100
  "mark_highlighting" => true,
103
101
  },
104
- }.each_with_object(Configuration.new) { |(k, v), hsh| hsh[k] = v.freeze }.freeze
105
102
 
106
- # TODO: Deprecated. Remove support for _config as well as toml in the next release.
107
- CONFIG_FILE_PREFIXES = %w(bridgetown.config _config).freeze
108
- CONFIG_FILE_EXTS = %w(yml yaml toml).freeze
103
+ "development" => {
104
+ "fast_refresh" => true,
105
+ },
106
+ }.each_with_object(Configuration.new) { |(k, v), hsh| hsh[k] = v.freeze }.freeze
109
107
 
110
108
  # @return [Hash<Symbol, Initializer>]
111
109
  attr_accessor :initializers
@@ -148,6 +146,7 @@ module Bridgetown
148
146
  dsl = ConfigurationDSL.new(scope: self, data: self)
149
147
  dsl.instance_variable_set(:@context, context)
150
148
  dsl.instance_exec(dsl, &init_init.block)
149
+ dsl._run_builtins!
151
150
  self.url = cached_url if cached_url # restore local development URL if need be
152
151
 
153
152
  setup_load_paths! appending: true
@@ -203,33 +202,8 @@ module Bridgetown
203
202
  end
204
203
  alias_method :verbose?, :verbose
205
204
 
206
- def safe_load_file(filename) # rubocop:todo Metrics
207
- case File.extname(filename)
208
- when %r!\.toml!i
209
- Deprecator.deprecation_message(
210
- "TOML configurations will no longer be supported in the next version of Bridgetown." \
211
- "Use initializers or a .yaml config instead."
212
- )
213
- Bridgetown::Utils::RequireGems.require_with_graceful_fail("tomlrb") unless defined?(Tomlrb)
214
- Tomlrb.load_file(filename)
215
- when %r!\.ya?ml!i
216
- if File.basename(filename, ".*") == "_config"
217
- Deprecator.deprecation_message(
218
- "YAML configurations named `_config.y(a)ml' will no longer be supported in the next " \
219
- "version of Bridgetown. Rename to `bridgetown.config.yml' instead."
220
- )
221
- end
222
- if File.extname(filename) == ".yaml"
223
- Deprecator.deprecation_message(
224
- "YAML configurations ending in `.yaml' will no longer be supported in the next " \
225
- "version of Bridgetown. Rename to use `.yml' extension instead."
226
- )
227
- end
228
- YAMLParser.load_file(filename) || {}
229
- else
230
- raise ArgumentError,
231
- "No parser for '#{filename}' is available. Use a .y(a)ml file instead."
232
- end
205
+ def safe_load_file(filename)
206
+ YAMLParser.load_file(filename) || {}
233
207
  rescue Psych::DisallowedClass => e
234
208
  raise "Unable to parse `#{File.basename(filename)}'. #{e.message}"
235
209
  end
@@ -251,28 +225,15 @@ module Bridgetown
251
225
  # By default only the first matching config file will be loaded, but
252
226
  # multiple configs can be specified via command line.
253
227
  config_files = override["config"]
254
- if config_files.to_s.empty?
255
- file_lookups = CONFIG_FILE_PREFIXES.map do |prefix|
256
- CONFIG_FILE_EXTS.map do |ext|
257
- Bridgetown.sanitized_path(root_dir(override), "#{prefix}.#{ext}")
258
- end
259
- end.flatten.freeze
260
-
261
- found_file = file_lookups.find do |path|
262
- File.exist?(path)
263
- end
264
-
265
- config_files = found_file || file_lookups.first
266
- @default_config_file = true
267
- end
228
+ config_files = "bridgetown.config.yml" if config_files.to_s.empty?
268
229
  Array(config_files)
269
230
  end
270
231
 
271
- # Public: Read in a list of configuration files and merge with this hash
232
+ # Read in a list of configuration files and merge with this hash
272
233
  #
273
- # files - the list of configuration file paths
234
+ # @param files [Array<String>]
274
235
  #
275
- # Returns the full configuration, with the defaults overridden by the values in the
236
+ # @return [Hash] configuration with the defaults overridden by the values in the
276
237
  # configuration files
277
238
  def read_config_files(files)
278
239
  config = self
@@ -293,30 +254,28 @@ module Bridgetown
293
254
  config
294
255
  end
295
256
 
296
- # Public: Read configuration and return merged Hash
257
+ # Read configuration and return merged Hash
297
258
  #
298
- # file - the path to the YAML file to be read in
259
+ # @param file [String] the path to the YAML file to be read in
299
260
  #
300
- # Returns this configuration, overridden by the values in the file
261
+ # @return [Hash]
301
262
  def read_config_file(file)
263
+ default_config_file = file == "bridgetown.config.yml"
302
264
  file = File.expand_path(file)
303
- next_config = safe_load_file(file)
265
+ # We don't care if default config is missing, we can return blank:
266
+ return {} if !File.exist?(file) && default_config_file
267
+
268
+ file_config = safe_load_file(file)
304
269
 
305
- unless next_config.is_a?(Hash)
270
+ unless file_config.is_a?(Hash)
306
271
  raise ArgumentError, "Configuration file: (INVALID) #{file}".yellow
307
272
  end
308
273
 
309
274
  Bridgetown.logger.debug "Configuration file:", file
310
- next_config
275
+ file_config
311
276
  rescue SystemCallError
312
- if @default_config_file ||= nil
313
- initializers_file = File.join(root_dir, "config", "initializers.rb")
314
- Bridgetown.logger.warn "Configuration file:", "none" unless File.file?(initializers_file)
315
- {}
316
- else
317
- Bridgetown.logger.error "Fatal:", "The configuration file '#{file}' could not be found."
318
- raise LoadError, "The Configuration file '#{file}' could not be found."
319
- end
277
+ Bridgetown.logger.error "Fatal:", "The configuration file '#{file}' could not be found."
278
+ raise LoadError, "missing configuration file"
320
279
  end
321
280
 
322
281
  # Merge in environment-specific options, if present
@@ -388,18 +347,12 @@ module Bridgetown
388
347
  self[:collections][:posts][:output] = true
389
348
  self[:collections][:posts][:sort_direction] ||= "descending"
390
349
 
391
- self[:permalink] = "pretty" if self[:permalink].blank?
392
350
  self[:collections][:pages] = {} unless self[:collections][:pages]
393
351
  self[:collections][:pages][:output] = true
394
- self[:collections][:pages][:permalink] ||= "/:locale/:path/"
395
352
 
396
353
  self[:collections][:data] = {} unless self[:collections][:data]
397
354
  self[:collections][:data][:output] = false
398
355
 
399
- unless self[:collections][:posts][:permalink]
400
- self[:collections][:posts][:permalink] = self[:permalink]
401
- end
402
-
403
356
  self
404
357
  end
405
358
 
@@ -6,7 +6,6 @@ unless File.exist?("postcss.config.js")
6
6
  error_message = "#{"postcss.config.js".bold} not found. Please configure postcss in your project."
7
7
 
8
8
  @logger.error "\nError:".red, "🚨 #{error_message}"
9
- @logger.info "\nRun #{"bridgetown webpack enable-postcss".bold.blue} to set it up.\n"
10
9
 
11
10
  return
12
11
  end
@@ -17,7 +16,7 @@ return unless confirm.casecmp?("Y")
17
16
  plugins = %w(postcss-mixins postcss-color-mod-function cssnano)
18
17
 
19
18
  say "Adding the following PostCSS plugins: #{plugins.join(' | ')}", :green
20
- run "yarn add -D #{plugins.join(' ')}"
19
+ add_npm_package "-D #{plugins.join(' ')}"
21
20
 
22
21
  copy_file in_templates_dir("postcss.config.js"), "postcss.config.js", force: true
23
22
 
@@ -1,12 +1,12 @@
1
1
  namespace :cy do
2
2
  desc "Open Cypress test runner"
3
3
  task :open do
4
- system "yarn run cypress open"
4
+ system "npm run cypress open"
5
5
  end
6
6
 
7
7
  desc "Run Cypress tests headless"
8
8
  task :run do
9
- system "yarn run cypress run"
9
+ system "npm run cypress run"
10
10
  end
11
11
 
12
12
  desc "Start server and open Cypress test runner"
@@ -3,7 +3,7 @@
3
3
  # Install packages
4
4
 
5
5
  say "Installing Cypress...", :green
6
- run "yarn add -D cypress"
6
+ add_npm_package "-D cypress"
7
7
 
8
8
  # Copy cypress files and tasks into place
9
9
  cypress_tasks = File.read(in_templates_dir("cypress_tasks"))
@@ -19,9 +19,9 @@ jobs:
19
19
  - name: Setup Node
20
20
  uses: actions/setup-node@v2
21
21
  with:
22
- node-version: "16"
23
- cache: "yarn"
24
- - run: yarn install
22
+ node-version: "20"
23
+ cache: "npm"
24
+ - run: npm install
25
25
 
26
26
  - name: Build
27
27
  env:
@@ -2,7 +2,7 @@
2
2
 
3
3
  say_status "is-land", "Installing <is-land>..."
4
4
 
5
- run "yarn add @11ty/is-land"
5
+ add_npm_package "@11ty/is-land"
6
6
 
7
7
  javascript_import do
8
8
  <<~JS
@@ -13,7 +13,7 @@ say_status :lit, "Installing Lit + SSR Plugin..."
13
13
 
14
14
  add_gem "bridgetown-lit-renderer", version: "2.1.0.beta2"
15
15
 
16
- run "yarn add lit esbuild-plugin-lit-css bridgetown-lit-renderer@2.1.0-beta2"
16
+ add_npm_package "lit esbuild-plugin-lit-css bridgetown-lit-renderer@2.1.0-beta2"
17
17
 
18
18
  copy_file in_templates_dir("lit-ssr.config.js"), "config/lit-ssr.config.js"
19
19
  copy_file in_templates_dir("lit-components-entry.js"), "config/lit-components-entry.js"
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- run "yarn add open-props"
3
+ add_npm_package "open-props"
4
4
 
5
5
  variables_import = <<~CSS
6
6
  @import "variables.css";
@@ -4,7 +4,7 @@
4
4
 
5
5
  say_status :purgecss, "Installing PurgeCSS"
6
6
 
7
- run "yarn add -D purgecss"
7
+ add_npm_package "-D purgecss"
8
8
 
9
9
  create_builder "purgecss.rb" do
10
10
  <<~RUBY
@@ -12,7 +12,7 @@ end
12
12
  say_status :ruby2js, "Installing Ruby2JS..."
13
13
 
14
14
  add_gem "ruby2js"
15
- run "yarn add -D @ruby2js/esbuild-plugin"
15
+ add_npm_package "-D @ruby2js/esbuild-plugin"
16
16
 
17
17
  insert_into_file "esbuild.config.js",
18
18
  after: 'const build = require("./config/esbuild.defaults.js")' do
@@ -2,7 +2,7 @@
2
2
 
3
3
  say_status :shoelace, "Installing Shoelace..."
4
4
 
5
- run "yarn add @shoelace-style/shoelace"
5
+ add_npm_package "@shoelace-style/shoelace"
6
6
 
7
7
  stylesheet_import = <<~CSS
8
8
  /* Import the base Shoelace stylesheet: */
@@ -37,26 +37,14 @@ end
37
37
 
38
38
  say "Updating frontend build commands...", :magenta
39
39
 
40
- if Bridgetown::Utils.frontend_bundler_type == :esbuild
41
- insert_into_file "package.json", before: ' "esbuild": "node' do
42
- <<-JS
43
- "shoelace:copy-assets": "mkdir -p src/shoelace-assets && cp -r node_modules/@shoelace-style/shoelace/dist/assets src/shoelace-assets",
44
- JS
45
- end
46
- gsub_file "package.json", %r{"esbuild": "node}, '"esbuild": "yarn shoelace:copy-assets && node'
47
- gsub_file "package.json", %r{"esbuild-dev": "node},
48
- '"esbuild-dev": "yarn shoelace:copy-assets && node'
49
- else
50
- insert_into_file "package.json", before: ' "webpack-build": "webpack' do
51
- <<-JS
52
- "shoelace:copy-assets": "mkdir -p src/shoelace-assets && cp -r node_modules/@shoelace-style/shoelace/dist/assets src/shoelace-assets",
53
- JS
54
- end
55
- gsub_file "package.json", %r{"webpack-build": "webpack},
56
- '"webpack-build": "yarn shoelace:copy-assets && webpack'
57
- gsub_file "package.json", %r{"webpack-dev": "webpack},
58
- '"webpack-dev": "yarn shoelace:copy-assets && webpack'
40
+ insert_into_file "package.json", before: ' "esbuild": "node' do
41
+ <<-JS
42
+ "shoelace:copy-assets": "mkdir -p src/shoelace-assets && cp -r node_modules/@shoelace-style/shoelace/dist/assets src/shoelace-assets",
43
+ JS
59
44
  end
45
+ gsub_file "package.json", %r{"esbuild": "node}, '"esbuild": "npm run shoelace:copy-assets && node'
46
+ gsub_file "package.json", %r{"esbuild-dev": "node},
47
+ '"esbuild-dev": "npm run shoelace:copy-assets && node'
60
48
 
61
49
  if File.exist?(".gitignore")
62
50
  append_to_file ".gitignore" do