bridgetown-core 0.21.2 → 1.0.0.alpha2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (127) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +35 -0
  3. data/Rakefile +5 -5
  4. data/bin/bridgetown +2 -0
  5. data/bridgetown-core.gemspec +3 -0
  6. data/lib/bridgetown-core/cache.rb +3 -5
  7. data/lib/bridgetown-core/cleaner.rb +2 -10
  8. data/lib/bridgetown-core/collection.rb +62 -86
  9. data/lib/bridgetown-core/commands/base.rb +62 -2
  10. data/lib/bridgetown-core/commands/build.rb +33 -12
  11. data/lib/bridgetown-core/commands/concerns/actions.rb +2 -2
  12. data/lib/bridgetown-core/commands/concerns/build_options.rb +3 -10
  13. data/lib/bridgetown-core/commands/concerns/configuration_overridable.rb +3 -1
  14. data/lib/bridgetown-core/commands/console.rb +3 -3
  15. data/lib/bridgetown-core/commands/doctor.rb +13 -11
  16. data/lib/bridgetown-core/commands/new.rb +14 -6
  17. data/lib/bridgetown-core/commands/plugins.rb +8 -11
  18. data/lib/bridgetown-core/commands/serve/servlet.rb +4 -4
  19. data/lib/bridgetown-core/commands/serve.rb +37 -37
  20. data/lib/bridgetown-core/commands/start.rb +106 -0
  21. data/lib/bridgetown-core/commands/webpack/webpack.defaults.js.erb +2 -2
  22. data/lib/bridgetown-core/commands/webpack.rb +1 -1
  23. data/lib/bridgetown-core/component.rb +1 -5
  24. data/lib/bridgetown-core/concerns/site/configurable.rb +1 -13
  25. data/lib/bridgetown-core/concerns/site/content.rb +17 -118
  26. data/lib/bridgetown-core/concerns/site/extensible.rb +3 -4
  27. data/lib/bridgetown-core/concerns/site/localizable.rb +3 -1
  28. data/lib/bridgetown-core/concerns/site/processable.rb +9 -20
  29. data/lib/bridgetown-core/concerns/site/renderable.rb +19 -30
  30. data/lib/bridgetown-core/concerns/site/ssr.rb +53 -0
  31. data/lib/bridgetown-core/concerns/site/writable.rb +6 -9
  32. data/lib/bridgetown-core/configuration.rb +19 -48
  33. data/lib/bridgetown-core/configurations/minitesting.rb +1 -1
  34. data/lib/bridgetown-core/configurations/turbo.rb +1 -1
  35. data/lib/bridgetown-core/converter.rb +1 -0
  36. data/lib/bridgetown-core/converters/erb_templates.rb +3 -2
  37. data/lib/bridgetown-core/converters/liquid_templates.rb +3 -2
  38. data/lib/bridgetown-core/converters/markdown/kramdown_parser.rb +1 -1
  39. data/lib/bridgetown-core/converters/smartypants.rb +1 -0
  40. data/lib/bridgetown-core/current.rb +4 -0
  41. data/lib/bridgetown-core/drops/collection_drop.rb +1 -1
  42. data/lib/bridgetown-core/drops/drop.rb +4 -4
  43. data/lib/bridgetown-core/drops/generated_page_drop.rb +23 -0
  44. data/lib/bridgetown-core/drops/resource_drop.rb +3 -3
  45. data/lib/bridgetown-core/drops/site_drop.rb +3 -47
  46. data/lib/bridgetown-core/entry_filter.rb +1 -0
  47. data/lib/bridgetown-core/errors.rb +0 -2
  48. data/lib/bridgetown-core/filters/url_filters.rb +2 -0
  49. data/lib/bridgetown-core/filters.rb +11 -12
  50. data/lib/bridgetown-core/frontmatter_defaults.rb +52 -90
  51. data/lib/bridgetown-core/{page.rb → generated_page.rb} +34 -60
  52. data/lib/bridgetown-core/generators/prototype_generator.rb +49 -61
  53. data/lib/bridgetown-core/helpers.rb +8 -3
  54. data/lib/bridgetown-core/hooks.rb +2 -2
  55. data/lib/bridgetown-core/layout.rb +15 -4
  56. data/lib/bridgetown-core/liquid_renderer.rb +1 -3
  57. data/lib/bridgetown-core/log_adapter.rb +1 -1
  58. data/lib/bridgetown-core/log_writer.rb +7 -1
  59. data/lib/bridgetown-core/model/base.rb +12 -4
  60. data/lib/bridgetown-core/model/builder_origin.rb +23 -11
  61. data/lib/bridgetown-core/model/origin.rb +3 -0
  62. data/lib/bridgetown-core/model/plugin_origin.rb +34 -0
  63. data/lib/bridgetown-core/model/repo_origin.rb +1 -1
  64. data/lib/bridgetown-core/plugin_manager.rb +10 -10
  65. data/lib/bridgetown-core/publisher.rb +1 -1
  66. data/lib/bridgetown-core/rack/boot.rb +47 -0
  67. data/lib/bridgetown-core/rack/logger.rb +22 -0
  68. data/lib/bridgetown-core/rack/roda.rb +66 -0
  69. data/lib/bridgetown-core/rack/routes.rb +88 -0
  70. data/lib/bridgetown-core/rack/static_indexes.rb +30 -0
  71. data/lib/bridgetown-core/reader.rb +20 -47
  72. data/lib/bridgetown-core/readers/layout_reader.rb +2 -2
  73. data/lib/bridgetown-core/readers/plugin_content_reader.rb +8 -7
  74. data/lib/bridgetown-core/renderer.rb +2 -12
  75. data/lib/bridgetown-core/resource/base.rb +51 -27
  76. data/lib/bridgetown-core/resource/permalink_processor.rb +23 -12
  77. data/lib/bridgetown-core/resource/relations.rb +2 -3
  78. data/lib/bridgetown-core/resource/taxonomy_term.rb +1 -5
  79. data/lib/bridgetown-core/resource/transformer.rb +8 -6
  80. data/lib/bridgetown-core/ruby_template_view.rb +6 -8
  81. data/lib/bridgetown-core/site.rb +4 -8
  82. data/lib/bridgetown-core/static_file.rb +14 -21
  83. data/lib/bridgetown-core/tags/find.rb +6 -6
  84. data/lib/bridgetown-core/tags/highlight.rb +5 -5
  85. data/lib/bridgetown-core/tags/include.rb +22 -32
  86. data/lib/bridgetown-core/tags/link.rb +4 -0
  87. data/lib/bridgetown-core/tags/live_reload_dev_js.rb +13 -0
  88. data/lib/bridgetown-core/tags/post_url.rb +9 -14
  89. data/lib/bridgetown-core/tags/render_content.rb +2 -2
  90. data/lib/bridgetown-core/tasks/bridgetown_tasks.rake +54 -0
  91. data/lib/bridgetown-core/url.rb +5 -4
  92. data/lib/bridgetown-core/utils/aux.rb +57 -0
  93. data/lib/bridgetown-core/utils/ruby_exec.rb +3 -45
  94. data/lib/bridgetown-core/utils/ruby_front_matter.rb +22 -7
  95. data/lib/bridgetown-core/utils.rb +60 -33
  96. data/lib/bridgetown-core/version.rb +2 -2
  97. data/lib/bridgetown-core/watcher.rb +4 -6
  98. data/lib/bridgetown-core.rb +16 -23
  99. data/lib/site_template/Gemfile.erb +6 -2
  100. data/lib/site_template/README.md +6 -6
  101. data/lib/site_template/Rakefile +49 -0
  102. data/lib/site_template/bridgetown.config.yml +2 -3
  103. data/lib/site_template/config/puma.rb +27 -0
  104. data/lib/site_template/config.ru +7 -0
  105. data/lib/site_template/frontend/javascript/index.js.erb +3 -3
  106. data/lib/site_template/package.json.erb +7 -12
  107. data/lib/site_template/server/roda_app.rb +22 -0
  108. data/lib/site_template/server/routes/hello.rb.sample +10 -0
  109. data/lib/site_template/src/_components/head.liquid +2 -1
  110. data/lib/site_template/src/about.md +0 -1
  111. data/lib/site_template/src/posts.md +2 -3
  112. metadata +63 -18
  113. data/lib/bridgetown-core/concerns/data_accessible.rb +0 -20
  114. data/lib/bridgetown-core/concerns/validatable.rb +0 -56
  115. data/lib/bridgetown-core/document.rb +0 -437
  116. data/lib/bridgetown-core/drops/document_drop.rb +0 -80
  117. data/lib/bridgetown-core/drops/excerpt_drop.rb +0 -19
  118. data/lib/bridgetown-core/drops/page_drop.rb +0 -18
  119. data/lib/bridgetown-core/excerpt.rb +0 -200
  120. data/lib/bridgetown-core/readers/data_reader.rb +0 -89
  121. data/lib/bridgetown-core/readers/page_reader.rb +0 -26
  122. data/lib/bridgetown-core/readers/post_reader.rb +0 -109
  123. data/lib/bridgetown-core/regenerator.rb +0 -202
  124. data/lib/bridgetown-core/related_posts.rb +0 -55
  125. data/lib/site_template/config/.keep +0 -0
  126. data/lib/site_template/start.js +0 -17
  127. data/lib/site_template/sync.js +0 -35
@@ -29,7 +29,7 @@ module Bridgetown
29
29
  end
30
30
 
31
31
  def ==(other)
32
- other.relative_path.match(@name_regex)
32
+ other.relative_path.to_s.match(@name_regex)
33
33
  end
34
34
 
35
35
  def deprecated_equality(other)
@@ -47,12 +47,7 @@ module Bridgetown
47
47
  #
48
48
  # Returns the post slug with the subdirectory (relative to _posts)
49
49
  def post_slug(other)
50
- path = other.basename.split("/")[0...-1].join("/")
51
- if path.nil? || path == ""
52
- other.data["slug"]
53
- else
54
- path + "/" + other.data["slug"]
55
- end
50
+ other.data.slug
56
51
  end
57
52
  end
58
53
 
@@ -77,21 +72,21 @@ module Bridgetown
77
72
  @context = context
78
73
  site = context.registers[:site]
79
74
 
80
- site.collections.posts.docs.each do |document|
75
+ site.collections.posts.resources.each do |document|
81
76
  return relative_url(document) if @post == document
82
- end
83
77
 
84
- # New matching method did not match, fall back to old method
85
- # with deprecation warning if this matches
86
-
87
- site.collections.posts.docs.each do |document|
78
+ # New matching method did not match, fall back to old method
79
+ # with deprecation warning if this matches
88
80
  next unless @post.deprecated_equality document
89
81
 
90
- Bridgetown::Deprecator.deprecation_message "A call to "\
82
+ Bridgetown::Deprecator.deprecation_message(
83
+ "A call to "\
91
84
  "'{% post_url #{@post.name} %}' did not match " \
92
85
  "a post using the new matching method of checking name " \
93
86
  "(path-date-slug) equality. Please make sure that you " \
94
87
  "change this tag to match the post's name exactly."
88
+ )
89
+
95
90
  return relative_url(document)
96
91
  end
97
92
 
@@ -3,7 +3,7 @@
3
3
  module Bridgetown
4
4
  module Tags
5
5
  class BlockRenderTag < Liquid::Block
6
- # rubocop:disable Metrics/MethodLength
6
+ # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
7
7
  def render(context)
8
8
  context.stack({}) do
9
9
  # unindent the incoming text
@@ -37,7 +37,7 @@ module Bridgetown
37
37
  .render_tag(context, +"")
38
38
  end
39
39
  end
40
- # rubocop:enable Metrics/MethodLength
40
+ # rubocop:enable Metrics/MethodLength, Metrics/AbcSize
41
41
 
42
42
  private
43
43
 
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ namespace :frontend do
4
+ desc "Run frontend bundler independently"
5
+ task :watcher, :sidecar do |_task, args|
6
+ # sidecar is when the task is running alongside the start command
7
+ sidecar = args[:sidecar] == true
8
+ Bridgetown::Utils::Aux.group do
9
+ run_process "Frontend", :yellow, "bundle exec bridgetown frontend:dev"
10
+ end
11
+ if sidecar
12
+ sleep 4 # give Webpack time to boot before returning control to the start command
13
+ else
14
+ trap("INT") do
15
+ Bridgetown::Utils::Aux.kill_processes
16
+ sleep 0.5
17
+ exit(0)
18
+ end
19
+ loop { sleep 1000 }
20
+ end
21
+ end
22
+ end
23
+
24
+ desc "Prerequisite task which loads site and provides automation"
25
+ task :environment do
26
+ class HammerActions < Thor # rubocop:disable Lint/ConstantDefinitionInBlock
27
+ include Thor::Actions
28
+ include Bridgetown::Commands::Actions
29
+
30
+ def self.source_root
31
+ Dir.pwd
32
+ end
33
+
34
+ def self.exit_on_failure?
35
+ true
36
+ end
37
+
38
+ private
39
+
40
+ def site
41
+ @site ||= Bridgetown::Site.new(Bridgetown.configuration)
42
+ end
43
+ end
44
+
45
+ define_singleton_method :automation do |*args, &block|
46
+ @hammer ||= HammerActions.new
47
+ @hammer.instance_exec(*args, &block)
48
+ end
49
+
50
+ define_singleton_method :site do
51
+ @hammer ||= HammerActions.new
52
+ @hammer.send(:site)
53
+ end
54
+ end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Public: Methods that generate a URL for a resource such as a Post or a Page.
3
+ # Public: Methods that generate a URL for GeneratedPage.
4
4
  #
5
5
  # Examples
6
6
  #
@@ -10,6 +10,7 @@
10
10
  # }).to_s
11
11
  #
12
12
  module Bridgetown
13
+ # TODO: remove this class in favor of the new Resource permalink processor
13
14
  class URL
14
15
  # options - One of :permalink or :template must be supplied.
15
16
  # :template - The String used as template for URL generation,
@@ -27,9 +28,9 @@ module Bridgetown
27
28
  @placeholders = options[:placeholders] || {}
28
29
  @permalink = options[:permalink]
29
30
 
30
- if (@template || @permalink).nil?
31
- raise ArgumentError, "One of :template or :permalink must be supplied."
32
- end
31
+ return unless (@template || @permalink).nil?
32
+
33
+ raise ArgumentError, "One of :template or :permalink must be supplied."
33
34
  end
34
35
 
35
36
  # The generated relative URL of the resource
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bridgetown
4
+ module Utils
5
+ module Aux
6
+ def self.with_color(name, message)
7
+ return message unless !name.nil? && Bridgetown::Utils::Ansi::COLORS[name.to_sym]
8
+
9
+ Bridgetown::Utils::Ansi.send(name, message)
10
+ end
11
+
12
+ def self.running_pids
13
+ @running_pids ||= []
14
+ end
15
+
16
+ def self.add_pid(pid)
17
+ running_pids << pid
18
+ end
19
+
20
+ def self.run_process(name, color, cmd)
21
+ Thread.new do
22
+ rd, wr = IO.pipe("BINARY")
23
+ pid = Process.spawn(cmd, out: wr, err: wr, pgroup: true)
24
+ @mutex.synchronize do
25
+ add_pid pid
26
+ end
27
+
28
+ loop do
29
+ line = rd.gets
30
+ line.to_s.lines.map(&:chomp).each do |message|
31
+ output = +""
32
+ output << with_color(color, "[#{name}] ") if color
33
+ output << message
34
+ @mutex.synchronize do
35
+ $stdout.puts output
36
+ $stdout.flush
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
42
+
43
+ def self.group(&block)
44
+ @mutex = Thread::Mutex.new
45
+ instance_exec(&block)
46
+ end
47
+
48
+ def self.kill_processes
49
+ Bridgetown.logger.info "Stopping auxiliary processes..."
50
+ running_pids.each do |pid|
51
+ Process.kill("SIGTERM", -Process.getpgid(pid))
52
+ rescue Errno::ESRCH, Errno::EPERM, Errno::ECHILD # rubocop:disable Lint/SuppressedException
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -3,10 +3,7 @@
3
3
  module Bridgetown
4
4
  module Utils
5
5
  module RubyExec
6
- extend self
7
-
8
- # TODO: Deprecate storing Ruby code in YAML, Rb, etc. and just use native Ruby Front Matter
9
- def search_data_for_ruby_code(convertible, renderer) # rubocop:todo Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
6
+ def self.search_data_for_ruby_code(convertible)
10
7
  return if convertible.data.empty?
11
8
 
12
9
  # Iterate using `keys` here so inline Ruby script can add new data keys
@@ -14,49 +11,10 @@ module Bridgetown
14
11
  data_keys = convertible.data.keys
15
12
  data_keys.each do |k|
16
13
  v = convertible.data[k]
17
- next unless v.is_a?(Rb) || v.is_a?(Hash) || v.is_a?(Proc)
18
-
19
- if v.is_a?(Proc)
20
- convertible.data[k] = convertible.instance_exec(&v)
21
- elsif v.is_a?(Hash)
22
- v.each do |nested_k, nested_v|
23
- next unless nested_v.is_a?(Rb)
24
-
25
- convertible.data[k][nested_k] = run(nested_v, convertible, renderer)
26
- end
27
- else
28
- convertible.data[k] = run(v, convertible, renderer)
29
- end
30
- end
31
- end
32
-
33
- # Sets up a new context in which to eval Ruby coming from front matter.
34
- #
35
- # ruby_code - a string of code
36
- # convertible - the Document/Page/Layout with the Ruby front matter
37
- # renderer - the Renderer instance that's processing the document (optional)
38
- #
39
- # Returns the transformed output of the code
40
- def run(ruby_code, convertible, renderer)
41
- return unless ruby_code.is_a?(Rb)
14
+ next unless v.is_a?(Proc)
42
15
 
43
- klass = Class.new
44
- obj = klass.new
45
-
46
- if convertible.is_a?(Layout)
47
- klass.attr_accessor :layout, :site, :data
48
- obj.layout = convertible
49
- else
50
- klass.attr_accessor :document, :page, :renderer, :site, :data
51
- obj.document = obj.page = convertible
52
- obj.renderer = renderer
16
+ convertible.data[k] = convertible.instance_exec(&v)
53
17
  end
54
- obj.site = convertible.site
55
- obj.data = convertible.data
56
-
57
- # This is where the magic happens! DON'T BE EVIL!!! ;-)
58
- output = obj.instance_eval(ruby_code)
59
- output.is_a?(Hash) ? output.with_dot_access : output
60
18
  end
61
19
  end
62
20
  end
@@ -3,20 +3,23 @@
3
3
  module Bridgetown
4
4
  module Utils
5
5
  module RubyFrontMatterDSL
6
- def front_matter(&block)
7
- RubyFrontMatter.new.tap { |fm| fm.instance_exec(&block) }
6
+ def front_matter(scope: nil, &block)
7
+ RubyFrontMatter.new(scope: scope).tap { |fm| fm.instance_exec(&block) }
8
8
  end
9
9
  end
10
10
 
11
11
  class RubyFrontMatter
12
- def initialize
12
+ def initialize(scope: nil)
13
13
  @data = {}
14
+ @scope = scope
14
15
  end
15
16
 
16
- def method_missing(key, value) # rubocop:disable Style/MissingRespondToMissing
17
- return super if respond_to?(key)
17
+ def method_missing(key, *value, &block) # rubocop:disable Metrics/CyclomaticComplexity, Style/MissingRespondToMissing
18
+ return super if respond_to?(key) || (value.length.zero? && block.nil? && !@data.key?(key))
18
19
 
19
- set(key, value)
20
+ return get(key) if value.length.zero? && block.nil? && @data.key?(key)
21
+
22
+ set(key, value[0], &block)
20
23
  end
21
24
 
22
25
  def each(&block)
@@ -27,7 +30,19 @@ module Bridgetown
27
30
  @data[key]
28
31
  end
29
32
 
30
- def set(key, value)
33
+ def set(key, value = nil, &block)
34
+ # Handle nested data within a block
35
+ if block
36
+ value = self.class.new(scope: @scope).tap do |fm|
37
+ fm.instance_exec(&block)
38
+ end.to_h
39
+ end
40
+
41
+ # Execute lambda value within the resolver
42
+ if @scope && value.is_a?(Hash) && value[:from].is_a?(Proc)
43
+ value = @scope.instance_exec(&value[:from])
44
+ end
45
+
31
46
  @data[key] = value
32
47
  end
33
48
 
@@ -1,16 +1,18 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Bridgetown
4
- module Utils
4
+ module Utils # rubocop:todo Metrics/ModuleLength
5
5
  extend self
6
6
  autoload :Ansi, "bridgetown-core/utils/ansi"
7
+ autoload :Aux, "bridgetown-core/utils/aux"
7
8
  autoload :RequireGems, "bridgetown-core/utils/require_gems"
8
9
  autoload :RubyExec, "bridgetown-core/utils/ruby_exec"
10
+ autoload :RubyFrontMatter, "bridgetown-core/utils/ruby_front_matter"
9
11
  autoload :RubyFrontMatterDSL, "bridgetown-core/utils/ruby_front_matter"
10
12
 
11
13
  # Constants for use in #slugify
12
14
  SLUGIFY_MODES = %w(raw default pretty simple ascii latin).freeze
13
- SLUGIFY_RAW_REGEXP = Regexp.new('\\s+').freeze
15
+ SLUGIFY_RAW_REGEXP = Regexp.new("\\s+").freeze
14
16
  SLUGIFY_DEFAULT_REGEXP = Regexp.new("[^\\p{M}\\p{L}\\p{Nd}]+").freeze
15
17
  SLUGIFY_PRETTY_REGEXP = Regexp.new("[^\\p{M}\\p{L}\\p{Nd}._~!$&'()+,;=@]+").freeze
16
18
  SLUGIFY_ASCII_REGEXP = Regexp.new("[^[A-Za-z0-9]]+").freeze
@@ -201,7 +203,7 @@ module Bridgetown
201
203
  slug = replace_character_sequence_with_hyphen(string, mode: mode)
202
204
 
203
205
  # Remove leading/trailing hyphen
204
- slug.gsub!(%r!^\-|\-$!i, "")
206
+ slug.gsub!(%r!^-|-$!i, "")
205
207
 
206
208
  slug.downcase! unless cased
207
209
 
@@ -314,9 +316,7 @@ module Bridgetown
314
316
  lines.map do |line|
315
317
  continue_processing = !skip_pre_lines
316
318
 
317
- if skip_pre_lines
318
- skip_pre_lines = false if line.include?("</pre>")
319
- end
319
+ skip_pre_lines = false if skip_pre_lines && line.include?("</pre>")
320
320
  if line.include?("<pre")
321
321
  skip_pre_lines = true
322
322
  continue_processing = false
@@ -338,7 +338,7 @@ module Bridgetown
338
338
  else
339
339
  line
340
340
  end
341
- end.join("")
341
+ end.join
342
342
  end
343
343
  # rubocop:enable Metrics/AbcSize, Metrics/MethodLength, Metrics/PerceivedComplexity
344
344
 
@@ -354,28 +354,19 @@ module Bridgetown
354
354
  # @raise [WebpackAssetError] if unable to find css or js in the manifest
355
355
  # file
356
356
  def parse_webpack_manifest_file(site, asset_type)
357
- manifest_file = site.in_root_dir(".bridgetown-webpack", "manifest.json")
358
- return "MISSING_WEBPACK_MANIFEST" unless File.exist?(manifest_file)
357
+ return log_webpack_asset_error("Webpack manifest") if site.frontend_manifest.nil?
359
358
 
360
- manifest = JSON.parse(File.read(manifest_file))
359
+ asset_path = if %w(js css).include?(asset_type)
360
+ site.frontend_manifest["main.#{asset_type}"]
361
+ else
362
+ site.frontend_manifest.find do |item, _|
363
+ item.sub(%r{^../(frontend/|src/)?}, "") == asset_type
364
+ end&.last
365
+ end
361
366
 
362
- known_assets = %w(js css)
363
- asset_path = nil
364
- if known_assets.include?(asset_type)
365
- asset_path = manifest["main.#{asset_type}"]
366
- log_webpack_asset_error(asset_type) && return if asset_path.nil?
367
- else
368
- asset_path = manifest.find do |item, _|
369
- item.sub(%r{^../(frontend/|src/)?}, "") == asset_type
370
- end&.last
371
- end
367
+ return log_webpack_asset_error(asset_type) if asset_path.nil?
372
368
 
373
- if asset_path
374
- static_frontend_path(site, ["js", asset_path])
375
- else
376
- Bridgetown.logger.error("Unknown Webpack asset type", asset_type)
377
- nil
378
- end
369
+ static_frontend_path site, ["js", asset_path]
379
370
  end
380
371
 
381
372
  def static_frontend_path(site, additional_parts = [])
@@ -389,10 +380,13 @@ module Bridgetown
389
380
  end
390
381
 
391
382
  def log_webpack_asset_error(asset_type)
392
- error_message = "There was an error parsing your #{asset_type} files. \
393
- Please check your #{asset_type} for any errors."
383
+ Bridgetown.logger.warn(
384
+ "Webpack:",
385
+ "There was an error parsing your #{asset_type} file. \
386
+ Please check your #{asset_type} file for any errors."
387
+ )
394
388
 
395
- Bridgetown.logger.warn(Errors::WebpackAssetError, error_message)
389
+ "MISSING_WEBPACK_MANIFEST_FILE"
396
390
  end
397
391
 
398
392
  def default_github_branch_name(repo_url)
@@ -404,6 +398,39 @@ module Bridgetown
404
398
  "master"
405
399
  end
406
400
 
401
+ def live_reload_js(site) # rubocop:disable Metrics/MethodLength
402
+ return "" unless Bridgetown.env.development? && !site.config.skip_live_reload
403
+
404
+ code = <<~JAVASCRIPT
405
+ let first_mod = 0
406
+ let connection_errors = 0
407
+ const checkForReload = () => {
408
+ fetch("/_bridgetown/live_reload").then(response => {
409
+ if (response.ok) {
410
+ response.json().then(data => {
411
+ const last_mod = data.last_mod
412
+ if (first_mod === 0) {
413
+ first_mod = last_mod
414
+ } else if (last_mod > first_mod) {
415
+ location.reload()
416
+ }
417
+ setTimeout(() => checkForReload(), 700)
418
+ })
419
+ } else {
420
+ if (connection_errors < 20) setTimeout(() => checkForReload(), 6000)
421
+ connection_errors++
422
+ }
423
+ }).catch((err) => {
424
+ if (connection_errors < 20) setTimeout(() => checkForReload(), 6000)
425
+ connection_errors++
426
+ })
427
+ }
428
+ checkForReload()
429
+ JAVASCRIPT
430
+
431
+ %(<script type="module">#{code}</script>).html_safe
432
+ end
433
+
407
434
  private
408
435
 
409
436
  def merge_values(target, overwrite)
@@ -419,9 +446,9 @@ module Bridgetown
419
446
  end
420
447
 
421
448
  def merge_default_proc(target, overwrite)
422
- if target.is_a?(Hash) && overwrite.is_a?(Hash) && target.default_proc.nil?
423
- target.default_proc = overwrite.default_proc
424
- end
449
+ return unless target.is_a?(Hash) && overwrite.is_a?(Hash) && target.default_proc.nil?
450
+
451
+ target.default_proc = overwrite.default_proc
425
452
  end
426
453
 
427
454
  def duplicate_frozen_values(target)
@@ -453,7 +480,7 @@ module Bridgetown
453
480
  end
454
481
 
455
482
  # Strip according to the mode
456
- string.gsub(replaceable_char, "-")
483
+ string.to_s.gsub(replaceable_char, "-")
457
484
  end
458
485
  end
459
486
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Bridgetown
4
- VERSION = "0.21.2"
5
- CODE_NAME = "Broughton Beach"
4
+ VERSION = "1.0.0.alpha2"
5
+ CODE_NAME = "Pearl"
6
6
  end
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "listen"
4
-
5
3
  module Bridgetown
6
4
  module Watcher
7
5
  extend self
@@ -19,9 +17,9 @@ module Bridgetown
19
17
  listener = build_listener(site, options)
20
18
  listener.start
21
19
 
22
- Bridgetown.logger.info "Auto-regeneration:", "enabled."
20
+ Bridgetown.logger.info "Auto-regeneration:", "enabled." unless options[:using_puma]
23
21
 
24
- unless options["serving"]
22
+ unless options[:serving]
25
23
  trap("INT") do
26
24
  listener.stop
27
25
  Bridgetown.logger.info "", "Halting auto-regeneration."
@@ -118,7 +116,7 @@ module Bridgetown
118
116
  rescue ArgumentError
119
117
  # Could not find a relative path
120
118
  end
121
- end.compact + [%r!^\.bridgetown\-metadata!]
119
+ end.compact + [%r!^\.bridgetown-metadata!]
122
120
  end
123
121
 
124
122
  def sleep_forever
@@ -134,7 +132,7 @@ module Bridgetown
134
132
  site.plugin_manager.reload_component_loaders
135
133
  site.process
136
134
  Bridgetown.logger.info "Done! 🎉", "#{"Completed".green} in less than" \
137
- " #{(Time.now - time).ceil(2)} seconds."
135
+ " #{(Time.now - time).ceil(2)} seconds."
138
136
  rescue Exception => e
139
137
  Bridgetown.logger.error "Error:", e.message
140
138
 
@@ -47,6 +47,7 @@ require "hash_with_dot_access"
47
47
  require "addressable/uri"
48
48
  require "liquid"
49
49
  require "liquid-component"
50
+ require "listen"
50
51
  require "kramdown"
51
52
  require "colorator"
52
53
  require "i18n"
@@ -66,53 +67,39 @@ end
66
67
  class Rb < String; end
67
68
 
68
69
  module Bridgetown
70
+ autoload :Cache, "bridgetown-core/cache"
71
+ autoload :Current, "bridgetown-core/current"
69
72
  autoload :Cleaner, "bridgetown-core/cleaner"
70
73
  autoload :Collection, "bridgetown-core/collection"
71
74
  autoload :Component, "bridgetown-core/component"
72
75
  autoload :Configuration, "bridgetown-core/configuration"
73
- autoload :DataAccessible, "bridgetown-core/concerns/data_accessible"
76
+ autoload :DefaultsReader, "bridgetown-core/readers/defaults_reader"
74
77
  autoload :Deprecator, "bridgetown-core/deprecator"
75
- autoload :Document, "bridgetown-core/document"
76
78
  autoload :EntryFilter, "bridgetown-core/entry_filter"
77
79
  # TODO: we have too many errors! This is silly
78
80
  autoload :Errors, "bridgetown-core/errors"
79
- autoload :Excerpt, "bridgetown-core/excerpt"
80
81
  autoload :FrontmatterDefaults, "bridgetown-core/frontmatter_defaults"
81
82
  autoload :FrontMatterImporter, "bridgetown-core/concerns/front_matter_importer"
83
+ autoload :GeneratedPage, "bridgetown-core/generated_page"
82
84
  autoload :Hooks, "bridgetown-core/hooks"
83
85
  autoload :Layout, "bridgetown-core/layout"
84
86
  autoload :LayoutPlaceable, "bridgetown-core/concerns/layout_placeable"
85
- autoload :Cache, "bridgetown-core/cache"
86
- autoload :Current, "bridgetown-core/current"
87
- # TODO: remove this when legacy content engine is gone:
88
- autoload :DataReader, "bridgetown-core/readers/data_reader"
89
- autoload :DefaultsReader, "bridgetown-core/readers/defaults_reader"
90
87
  autoload :LayoutReader, "bridgetown-core/readers/layout_reader"
91
- # TODO: remove this when legacy content engine is gone:
92
- autoload :PostReader, "bridgetown-core/readers/post_reader"
93
- # TODO: remove this when legacy content engine is gone:
94
- autoload :PageReader, "bridgetown-core/readers/page_reader"
95
- autoload :PluginContentReader, "bridgetown-core/readers/plugin_content_reader"
88
+ autoload :LiquidRenderable, "bridgetown-core/concerns/liquid_renderable"
89
+ autoload :LiquidRenderer, "bridgetown-core/liquid_renderer"
96
90
  autoload :LogAdapter, "bridgetown-core/log_adapter"
97
- autoload :Page, "bridgetown-core/page"
98
- autoload :GeneratedPage, "bridgetown-core/page"
91
+ autoload :PluginContentReader, "bridgetown-core/readers/plugin_content_reader"
99
92
  autoload :PluginManager, "bridgetown-core/plugin_manager"
100
93
  autoload :Publishable, "bridgetown-core/concerns/publishable"
101
94
  autoload :Publisher, "bridgetown-core/publisher"
102
95
  autoload :Reader, "bridgetown-core/reader"
103
- # TODO: remove this when the incremental regenerator is gone:
104
- autoload :Regenerator, "bridgetown-core/regenerator"
105
- autoload :RelatedPosts, "bridgetown-core/related_posts"
106
96
  autoload :Renderer, "bridgetown-core/renderer"
107
- autoload :LiquidRenderable, "bridgetown-core/concerns/liquid_renderable"
108
- autoload :LiquidRenderer, "bridgetown-core/liquid_renderer"
109
97
  autoload :RubyTemplateView, "bridgetown-core/ruby_template_view"
110
98
  autoload :LogWriter, "bridgetown-core/log_writer"
111
99
  autoload :Site, "bridgetown-core/site"
112
100
  autoload :StaticFile, "bridgetown-core/static_file"
113
101
  autoload :URL, "bridgetown-core/url"
114
102
  autoload :Utils, "bridgetown-core/utils"
115
- autoload :Validatable, "bridgetown-core/concerns/validatable"
116
103
  autoload :VERSION, "bridgetown-core/version"
117
104
  autoload :Watcher, "bridgetown-core/watcher"
118
105
  autoload :YAMLParser, "bridgetown-core/yaml_parser"
@@ -126,7 +113,6 @@ module Bridgetown
126
113
  require "bridgetown-core/filters"
127
114
 
128
115
  require "bridgetown-core/drops/drop"
129
- require "bridgetown-core/drops/document_drop"
130
116
  require "bridgetown-core/drops/resource_drop"
131
117
  require_all "bridgetown-core/converters"
132
118
  require_all "bridgetown-core/converters/markdown"
@@ -173,6 +159,12 @@ module Bridgetown
173
159
  Bridgetown::Commands::Registrations.register(&block)
174
160
  end
175
161
 
162
+ def load_tasks
163
+ require "bridgetown-core/commands/base"
164
+ Bridgetown::PluginManager.require_from_bundler
165
+ load File.expand_path("bridgetown-core/tasks/bridgetown_tasks.rake", __dir__)
166
+ end
167
+
176
168
  # Determines the correct Bundler environment block method to use and passes
177
169
  # the block on to it.
178
170
  #
@@ -257,12 +249,13 @@ end
257
249
 
258
250
  module Bridgetown
259
251
  module Model; end
252
+
260
253
  module Resource
261
254
  def self.register_extension(mod)
262
255
  if mod.const_defined?(:LiquidResource)
263
256
  Bridgetown::Drops::ResourceDrop.include mod.const_get(:LiquidResource)
264
257
  end
265
- if mod.const_defined?(:RubyResource)
258
+ if mod.const_defined?(:RubyResource) # rubocop:disable Style/GuardClause
266
259
  Bridgetown::Resource::Base.include mod.const_get(:RubyResource)
267
260
  end
268
261
  end
@@ -3,9 +3,9 @@ git_source(:github) { |repo| "https://github.com/#{repo}.git" }
3
3
 
4
4
  # Hello! This is where you manage which Bridgetown version is used to run.
5
5
  # When you want to use a different version, change it below, save the
6
- # file and run `bundle install`. Run Bridgetown with `bundle exec`, like so:
6
+ # file and run `bundle install`. Run Bridgetown like so:
7
7
  #
8
- # bundle exec bridgetown serve
8
+ # bin/bridgetown start (or console, etc.)
9
9
  #
10
10
  # This will help ensure the proper Bridgetown version is running.
11
11
  #
@@ -17,3 +17,7 @@ git_source(:github) { |repo| "https://github.com/#{repo}.git" }
17
17
  # Happy Bridgetowning!
18
18
 
19
19
  gem "bridgetown", "~> <%= Bridgetown::VERSION %>"
20
+
21
+ # Puma is a Rack-compatible server
22
+ # (you can optionally limit this to the "development" group)
23
+ gem "puma", "~> 5.2"