bridgetown-core 0.21.1 → 1.0.0.alpha1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (103) hide show
  1. checksums.yaml +4 -4
  2. data/bin/bridgetown +2 -0
  3. data/bridgetown-core.gemspec +3 -0
  4. data/lib/bridgetown-core/cleaner.rb +0 -8
  5. data/lib/bridgetown-core/collection.rb +59 -81
  6. data/lib/bridgetown-core/commands/base.rb +60 -1
  7. data/lib/bridgetown-core/commands/build.rb +26 -6
  8. data/lib/bridgetown-core/commands/concerns/build_options.rb +3 -10
  9. data/lib/bridgetown-core/commands/concerns/configuration_overridable.rb +3 -1
  10. data/lib/bridgetown-core/commands/doctor.rb +3 -3
  11. data/lib/bridgetown-core/commands/new.rb +9 -3
  12. data/lib/bridgetown-core/commands/plugins.rb +1 -2
  13. data/lib/bridgetown-core/commands/serve.rb +14 -12
  14. data/lib/bridgetown-core/commands/start.rb +106 -0
  15. data/lib/bridgetown-core/commands/webpack/webpack.defaults.js.erb +2 -2
  16. data/lib/bridgetown-core/concerns/site/configurable.rb +0 -12
  17. data/lib/bridgetown-core/concerns/site/content.rb +16 -117
  18. data/lib/bridgetown-core/concerns/site/localizable.rb +3 -1
  19. data/lib/bridgetown-core/concerns/site/processable.rb +9 -20
  20. data/lib/bridgetown-core/concerns/site/renderable.rb +19 -30
  21. data/lib/bridgetown-core/concerns/site/ssr.rb +53 -0
  22. data/lib/bridgetown-core/concerns/site/writable.rb +5 -8
  23. data/lib/bridgetown-core/configuration.rb +18 -47
  24. data/lib/bridgetown-core/configurations/minitesting.rb +1 -1
  25. data/lib/bridgetown-core/configurations/turbo.rb +1 -1
  26. data/lib/bridgetown-core/converters/erb_templates.rb +2 -1
  27. data/lib/bridgetown-core/converters/liquid_templates.rb +3 -2
  28. data/lib/bridgetown-core/current.rb +4 -0
  29. data/lib/bridgetown-core/drops/collection_drop.rb +1 -1
  30. data/lib/bridgetown-core/drops/generated_page_drop.rb +23 -0
  31. data/lib/bridgetown-core/drops/resource_drop.rb +3 -3
  32. data/lib/bridgetown-core/drops/site_drop.rb +3 -47
  33. data/lib/bridgetown-core/errors.rb +0 -2
  34. data/lib/bridgetown-core/filters/url_filters.rb +3 -1
  35. data/lib/bridgetown-core/frontmatter_defaults.rb +52 -88
  36. data/lib/bridgetown-core/{page.rb → generated_page.rb} +34 -58
  37. data/lib/bridgetown-core/generators/prototype_generator.rb +13 -24
  38. data/lib/bridgetown-core/helpers.rb +7 -2
  39. data/lib/bridgetown-core/layout.rb +15 -4
  40. data/lib/bridgetown-core/log_writer.rb +6 -0
  41. data/lib/bridgetown-core/model/base.rb +10 -2
  42. data/lib/bridgetown-core/model/builder_origin.rb +22 -10
  43. data/lib/bridgetown-core/model/origin.rb +3 -0
  44. data/lib/bridgetown-core/model/plugin_origin.rb +34 -0
  45. data/lib/bridgetown-core/model/repo_origin.rb +1 -1
  46. data/lib/bridgetown-core/plugin_manager.rb +8 -8
  47. data/lib/bridgetown-core/rack/boot.rb +47 -0
  48. data/lib/bridgetown-core/rack/logger.rb +22 -0
  49. data/lib/bridgetown-core/rack/roda.rb +66 -0
  50. data/lib/bridgetown-core/rack/routes.rb +92 -0
  51. data/lib/bridgetown-core/rack/static_indexes.rb +30 -0
  52. data/lib/bridgetown-core/reader.rb +20 -47
  53. data/lib/bridgetown-core/readers/plugin_content_reader.rb +8 -7
  54. data/lib/bridgetown-core/renderer.rb +1 -11
  55. data/lib/bridgetown-core/resource/base.rb +50 -26
  56. data/lib/bridgetown-core/resource/permalink_processor.rb +20 -10
  57. data/lib/bridgetown-core/resource/relations.rb +2 -3
  58. data/lib/bridgetown-core/resource/transformer.rb +1 -1
  59. data/lib/bridgetown-core/ruby_template_view.rb +5 -5
  60. data/lib/bridgetown-core/site.rb +4 -8
  61. data/lib/bridgetown-core/static_file.rb +10 -15
  62. data/lib/bridgetown-core/tags/include.rb +0 -13
  63. data/lib/bridgetown-core/tags/link.rb +4 -0
  64. data/lib/bridgetown-core/tags/live_reload_dev_js.rb +13 -0
  65. data/lib/bridgetown-core/tags/post_url.rb +4 -9
  66. data/lib/bridgetown-core/tasks/bridgetown_tasks.rake +54 -0
  67. data/lib/bridgetown-core/url.rb +2 -1
  68. data/lib/bridgetown-core/utils/aux.rb +57 -0
  69. data/lib/bridgetown-core/utils/ruby_exec.rb +3 -45
  70. data/lib/bridgetown-core/utils/ruby_front_matter.rb +22 -7
  71. data/lib/bridgetown-core/utils.rb +53 -24
  72. data/lib/bridgetown-core/version.rb +2 -2
  73. data/lib/bridgetown-core/watcher.rb +2 -4
  74. data/lib/bridgetown-core.rb +14 -22
  75. data/lib/site_template/Gemfile.erb +6 -2
  76. data/lib/site_template/README.md +6 -6
  77. data/lib/site_template/Rakefile +49 -0
  78. data/lib/site_template/bridgetown.config.yml +2 -3
  79. data/lib/site_template/config/puma.rb +27 -0
  80. data/lib/site_template/config.ru +7 -0
  81. data/lib/site_template/frontend/javascript/index.js.erb +3 -3
  82. data/lib/site_template/package.json.erb +8 -13
  83. data/lib/site_template/server/roda_app.rb +22 -0
  84. data/lib/site_template/server/routes/hello.rb.sample +10 -0
  85. data/lib/site_template/src/_components/head.liquid +2 -1
  86. data/lib/site_template/src/about.md +0 -1
  87. data/lib/site_template/src/posts.md +2 -3
  88. metadata +62 -18
  89. data/lib/bridgetown-core/concerns/data_accessible.rb +0 -20
  90. data/lib/bridgetown-core/concerns/validatable.rb +0 -56
  91. data/lib/bridgetown-core/document.rb +0 -437
  92. data/lib/bridgetown-core/drops/document_drop.rb +0 -80
  93. data/lib/bridgetown-core/drops/excerpt_drop.rb +0 -19
  94. data/lib/bridgetown-core/drops/page_drop.rb +0 -18
  95. data/lib/bridgetown-core/excerpt.rb +0 -200
  96. data/lib/bridgetown-core/readers/data_reader.rb +0 -89
  97. data/lib/bridgetown-core/readers/page_reader.rb +0 -26
  98. data/lib/bridgetown-core/readers/post_reader.rb +0 -109
  99. data/lib/bridgetown-core/regenerator.rb +0 -202
  100. data/lib/bridgetown-core/related_posts.rb +0 -55
  101. data/lib/site_template/config/.keep +0 -0
  102. data/lib/site_template/start.js +0 -17
  103. data/lib/site_template/sync.js +0 -35
@@ -0,0 +1,106 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bridgetown
4
+ module Commands
5
+ class Start < Thor::Group
6
+ extend BuildOptions
7
+ extend Summarizable
8
+ include ConfigurationOverridable
9
+
10
+ Registrations.register do
11
+ register(Start, "start", "start", Start.summary)
12
+ register(Start, "dev", "dev", "Alias of start")
13
+ end
14
+
15
+ class_option :bind, aliases: "-B", desc: "URI for Puma to bind to (start with tcp://)"
16
+ class_option :skip_frontend,
17
+ type: :boolean,
18
+ desc: "Don't load the frontend bundler (always true for production)"
19
+ class_option :skip_live_reload,
20
+ type: :boolean,
21
+ desc: "Don't use the live reload functionality (always true for production)"
22
+
23
+ def self.banner
24
+ "bridgetown start [options]"
25
+ end
26
+ summary "Start the Puma server, frontend bundler, and Bridgetown watcher"
27
+
28
+ def start # rubocop:todo Metrics/PerceivedComplexity
29
+ Bridgetown.logger.writer.enable_prefix
30
+ Bridgetown::Commands::Build.print_startup_message
31
+ sleep 0.25
32
+
33
+ unless Bundler.definition.specs.find { |s| s.name == "puma" }
34
+ raise "** No Rack-compatible server found **"
35
+ end
36
+
37
+ options = Thor::CoreExt::HashWithIndifferentAccess.new(self.options)
38
+ options[:using_puma] = true
39
+
40
+ # Load Bridgetown configuration into thread memory
41
+ bt_options = configuration_with_overrides(options)
42
+
43
+ puma_pid =
44
+ Process.fork do
45
+ require "puma/cli"
46
+
47
+ Puma::Runner.class_eval do
48
+ def output_header(mode)
49
+ log "* Puma version: #{Puma::Const::PUMA_VERSION} (#{ruby_engine}) (\"#{Puma::Const::CODE_NAME}\")" # rubocop:disable Layout/LineLength
50
+ if mode == "cluster"
51
+ log "* Cluster Master PID: #{Process.pid}"
52
+ else
53
+ log "* PID: #{Process.pid}"
54
+ end
55
+ end
56
+ end
57
+
58
+ puma_args = []
59
+ if bt_options[:bind]
60
+ puma_args << "--bind"
61
+ puma_args << bt_options[:bind]
62
+ end
63
+
64
+ cli = Puma::CLI.new puma_args
65
+ cli.run
66
+ end
67
+
68
+ begin
69
+ unless Bridgetown.env.production? || options[:skip_frontend]
70
+ require "rake"
71
+ Rake.with_application do |rake|
72
+ rake.load_rakefile
73
+ rake["frontend:watcher"].invoke(true)
74
+ end
75
+ end
76
+
77
+ Signal.trap("TERM") do
78
+ Process.kill "SIGINT", puma_pid
79
+ sleep 0.5 # let it breathe
80
+ exit 0 # this runs the ensure block below
81
+ end
82
+
83
+ Process.setproctitle("bridgetown #{Bridgetown::VERSION} [#{File.basename(Dir.pwd)}]")
84
+
85
+ build_args = ["-w"] + ARGV.reject { |arg| arg == "start" }
86
+ if Bridgetown.env.development? && !options["url"]
87
+ scheme = bt_options.bind&.split("://")&.first == "ssl" ? "https" : "http"
88
+ port = bt_options.bind&.split(":")&.last || ENV["BRIDGETOWN_PORT"] || 4000
89
+ build_args << "--url"
90
+ build_args << "#{scheme}://localhost:#{port}"
91
+ end
92
+ Bridgetown::Commands::Build.start(build_args)
93
+ rescue StandardError => e
94
+ Process.kill "SIGINT", puma_pid
95
+ sleep 0.5
96
+ raise e
97
+ ensure
98
+ # Shut down webpack, browsersync, etc. if they're running
99
+ Bridgetown::Utils::Aux.kill_processes
100
+ end
101
+
102
+ sleep 0.5 # finish cleaning up
103
+ end
104
+ end
105
+ end
106
+ end
@@ -24,8 +24,8 @@ const output = {
24
24
 
25
25
  // Rules and Loaders
26
26
 
27
- const jsRule = {
28
- test: /\.(js|jsx)/,
27
+ const jsRule = {
28
+ test: /\.(js|jsx)$/,
29
29
  use: {
30
30
  loader: "esbuild-loader",
31
31
  options: {
@@ -62,18 +62,6 @@ class Bridgetown::Site
62
62
  @frontmatter_defaults ||= Bridgetown::FrontmatterDefaults.new(self)
63
63
  end
64
64
 
65
- # Whether to perform a full rebuild without incremental regeneration.
66
- # If either `override["incremental"]` or `config["incremental"]` are true,
67
- # fully rebuild the site. If not, incrementally build the site.
68
- #
69
- # @param [Hash] override
70
- # An override hash to override the current config value
71
- # @option override [Boolean] "incremental" Whether to incrementally build
72
- # @return [Boolean] true for full rebuild, false for normal build
73
- def incremental?(override = {})
74
- override["incremental"] || config["incremental"]
75
- end
76
-
77
65
  # Returns the current instance of {Publisher} or creates a new instance of
78
66
  # {Publisher} if one doesn't exist.
79
67
  #
@@ -3,37 +3,9 @@
3
3
  class Bridgetown::Site
4
4
  # Content is king!
5
5
  module Content
6
- # Construct a Hash of Posts indexed by the specified Post attribute.
7
- #
8
- # Returns a hash like so: `{ attr => posts }` where:
9
- #
10
- # * `attr` - One of the values for the requested attribute.
11
- # * `posts` - The array of Posts with the given attr value.
12
- #
13
- # @param post_attr [String] The String name of the Post attribute.
14
- #
15
- # @example
16
- # post_attr_hash('categories')
17
- # # => { 'tech' => [<Post A>, <Post B>],
18
- # # 'ruby' => [<Post B>] }
19
- #
20
- # @return [Hash{String, Symbol => Array<Post>}]
21
- # Returns a hash of !{attr => posts}
22
- def post_attr_hash(post_attr)
23
- # Build a hash map based on the specified post attribute ( post attr =>
24
- # array of posts ) then sort each array in reverse order.
25
- @post_attr_hash[post_attr] ||= begin
26
- hash = Hash.new { |h, key| h[key] = [] }
27
- posts.docs.each do |p|
28
- p.data[post_attr]&.each { |t| hash[t] << p }
29
- end
30
- hash.each_value { |posts| posts.sort!.reverse! }
31
- hash
32
- end
33
- end
34
-
35
6
  def resources_grouped_by_taxonomy(taxonomy)
36
- @post_attr_hash[taxonomy.label] ||= begin
7
+ data.site_taxonomies_hash ||= {}
8
+ data.site_taxonomies_hash[taxonomy.label] ||= begin
37
9
  taxonomy.terms.transform_values { |terms| terms.map(&:resource).sort.reverse }
38
10
  end
39
11
  end
@@ -44,29 +16,12 @@ class Bridgetown::Site
44
16
  end
45
17
  end
46
18
 
47
- # Returns a hash of "tags" using {#post_attr_hash} where each tag is a key
48
- # and each value is a post which contains the key.
49
- # @example
50
- # tags
51
- # # => { 'tech': [<Post A>, <Post B>],
52
- # # 'ruby': [<Post C> }
53
- # @return [Hash{String, Array<Post>}] Returns a hash of all tags and their corresponding posts
54
- # @see post_attr_hash
55
19
  def tags
56
- uses_resource? ? taxonomies.tag : post_attr_hash("tags")
20
+ taxonomies.tag
57
21
  end
58
22
 
59
- # Returns a hash of "categories" using {#post_attr_hash} where each tag is
60
- # a key and each value is a post which contains the key.
61
- # @example
62
- # categories
63
- # # => { 'tech': [<Post A>, <Post B>],
64
- # # 'ruby': [<Post C> }
65
- # @return [Hash{String, Array<Post>}] Returns a hash of all categories and
66
- # their corresponding posts
67
- # @see post_attr_hash
68
23
  def categories
69
- uses_resource? ? taxonomies.category : post_attr_hash("categories")
24
+ taxonomies.category
70
25
  end
71
26
 
72
27
  # Returns the value of `data["site_metadata"]` or creates a new instance of
@@ -78,34 +33,7 @@ class Bridgetown::Site
78
33
 
79
34
  # The Hash payload containing site-wide data.
80
35
  #
81
- # @example
82
- # site_payload
83
- # # => { "site" => data } Where data is a Hash. See example below
84
- #
85
- # site = site_payload["site"]
86
- # # => Returns a Hash with the following keys:
87
- # #
88
- # # site["time"] - The Time as specified in the configuration or the
89
- # # current time if none was specified.
90
- # #
91
- # # site["posts"] - The Array of Posts, sorted chronologically by post date
92
- # # and then title.
93
- # #
94
- # # site["pages"] - The Array of all Pages.
95
- # #
96
- # # site["html_pages"] - The Array of HTML Pages.
97
- # #
98
- # # site["categories"] - The Hash of category values and Posts.
99
- # # See Site#post_attr_hash for type info.
100
- # #
101
- # # site["tags"] - The Hash of tag values and Posts.
102
- # # See Site#post_attr_hash for type info.
103
- #
104
36
  # @return [Hash] Returns a hash in the structure of { "site" => data }
105
- #
106
- # See above example for usage.
107
- #
108
- # @see #post_attr_hash
109
37
  def site_payload
110
38
  Bridgetown::Drops::UnifiedPayloadDrop.new self
111
39
  end
@@ -154,25 +82,6 @@ class Bridgetown::Site
154
82
  end.to_h.with_dot_access
155
83
  end
156
84
 
157
- # Get all documents.
158
- # @return [Array<Document>] an array of documents from the
159
- # configuration
160
- def documents
161
- collections.each_with_object(Set.new) do |(_, collection), set|
162
- set.merge(collection.docs)
163
- end.to_a
164
- end
165
-
166
- # Get the documents to be written
167
- #
168
- # @return [Array<Document>] an array of documents which should be
169
- # written and that `respond_to :write?`
170
- # @see #documents
171
- # @see Collection
172
- def docs_to_write
173
- documents.select(&:write?)
174
- end
175
-
176
85
  # Get all loaded resources.
177
86
  # @return [Array<Bridgetown::Resource::Base>] an array of resources
178
87
  def resources
@@ -181,23 +90,12 @@ class Bridgetown::Site
181
90
  end.to_a
182
91
  end
183
92
 
93
+ alias_method :contents, :resources
94
+
184
95
  def resources_to_write
185
96
  resources.select(&:write?)
186
97
  end
187
98
 
188
- # Get all posts. Deprecated, to be removed in v1.0.
189
- #
190
- # @return [Collection] Returns {#collections}`["posts"]`, creating it if need be
191
- # @see Collection
192
- def posts
193
- unless @wrote_deprecation_msg
194
- Bridgetown::Deprecator.deprecation_message "Call site.collections.posts " \
195
- "instead of site.posts (Ruby code)"
196
- end
197
- @wrote_deprecation_msg ||= true
198
- collections["posts"] ||= Bridgetown::Collection.new(self, "posts")
199
- end
200
-
201
99
  # Get the static files to be written
202
100
  #
203
101
  # @return [Array<StaticFile>] an array of files which should be
@@ -208,17 +106,18 @@ class Bridgetown::Site
208
106
  static_files.select(&:write?)
209
107
  end
210
108
 
211
- # Get all pages and documents (posts and collection items) in a single array.
212
- #
213
- # @return [Array]
214
- def contents
215
- return resources if uses_resource?
216
-
217
- pages + documents
218
- end
219
-
220
109
  def add_generated_page(generated_page)
221
110
  generated_pages << generated_page
222
111
  end
112
+
113
+ # Loads and memoizes the parsed Webpack manifest file (if available)
114
+ # @return [Hash]
115
+ def frontend_manifest
116
+ @frontend_manifest ||= begin
117
+ manifest_file = in_root_dir(".bridgetown-webpack", "manifest.json")
118
+
119
+ JSON.parse(File.read(manifest_file)) if File.exist?(manifest_file)
120
+ end
121
+ end
223
122
  end
224
123
  end
@@ -7,7 +7,9 @@ class Bridgetown::Site
7
7
  def locale
8
8
  @locale ||= begin
9
9
  locale = ENV.fetch("BRIDGETOWN_LOCALE", config[:default_locale]).to_sym
10
- I18n.load_path << Dir[in_source_dir("_locales") + "/*.yml"]
10
+ Dir[in_source_dir("_locales") + "/*.yml"].each do |locale_path|
11
+ I18n.load_path << locale_path
12
+ end
11
13
  I18n.available_locales = config[:available_locales]
12
14
  I18n.default_locale = locale
13
15
  end
@@ -22,8 +22,10 @@ class Bridgetown::Site
22
22
  end
23
23
 
24
24
  # Reset all in-memory data and content.
25
+ #
26
+
25
27
  # @return [void]
26
- def reset
28
+ def reset(soft: false)
27
29
  self.time = Time.now
28
30
  if config["time"]
29
31
  self.time = Bridgetown::Utils.parse_date(
@@ -31,19 +33,18 @@ class Bridgetown::Site
31
33
  )
32
34
  end
33
35
  self.layouts = HashWithDotAccess::Hash.new
34
- self.pages = []
36
+ self.generated_pages = []
35
37
  self.static_files = []
36
- self.data = HashWithDotAccess::Hash.new
37
- @post_attr_hash = {}
38
+ self.data = HashWithDotAccess::Hash.new unless soft
39
+ @frontend_manifest = nil
38
40
  @collections = nil
39
41
  @documents = nil
40
42
  @docs_to_write = nil
41
- @regenerator.clear_cache
42
43
  @liquid_renderer.reset
43
- frontmatter_defaults.reset
44
+ frontmatter_defaults.reset unless soft
44
45
 
45
- Bridgetown::Cache.clear_if_config_changed config
46
- Bridgetown::Hooks.trigger :site, :after_reset, self
46
+ Bridgetown::Cache.clear_if_config_changed config unless soft
47
+ Bridgetown::Hooks.trigger :site, (soft ? :after_soft_reset : :after_reset), self
47
48
  end
48
49
 
49
50
  # Read data from disk and load it into internal memory.
@@ -51,23 +52,11 @@ class Bridgetown::Site
51
52
  def read
52
53
  Bridgetown::Hooks.trigger :site, :pre_read, self
53
54
  reader.read
54
- limit_posts!
55
55
  Bridgetown::Hooks.trigger :site, :post_read, self
56
56
  end
57
57
 
58
58
  private
59
59
 
60
- # Limits the current posts; removes the posts which exceed the limit_posts
61
- def limit_posts!
62
- if config.limit_posts.positive?
63
- Bridgetown::Deprecator.deprecation_message(
64
- "The limit_posts config option will be removed prior to Bridgetown 1.0"
65
- )
66
- limit = posts.docs.length < config.limit_posts ? posts.docs.length : config.limit_posts
67
- posts.docs = posts.docs[-limit, limit]
68
- end
69
- end
70
-
71
60
  def print_stats
72
61
  Bridgetown.logger.info @liquid_renderer.stats_table
73
62
  end
@@ -9,23 +9,20 @@ class Bridgetown::Site
9
9
  def render
10
10
  Bridgetown::Hooks.trigger :site, :pre_render, self
11
11
  execute_inline_ruby_for_layouts!
12
- render_docs
13
- render_pages
12
+ render_resources
13
+ render_generated_pages
14
14
  Bridgetown::Hooks.trigger :site, :post_render, self
15
15
  end
16
16
 
17
- # Executes inline Ruby frontmatter
17
+ # Executes procs in Ruby frontmatter
18
18
  #
19
- # @example
20
- # calculation: !ruby/string:Rb |
21
- # [2 * 4, 5 + 2].min
22
19
  # @return [void]
23
20
  # @see https://www.bridgetownrb.com/docs/front-matter#ruby-front-matter
24
21
  def execute_inline_ruby_for_layouts!
25
22
  return unless config.should_execute_inline_ruby?
26
23
 
27
24
  layouts.each_value do |layout|
28
- Bridgetown::Utils::RubyExec.search_data_for_ruby_code(layout, self)
25
+ Bridgetown::Utils::RubyExec.search_data_for_ruby_code(layout)
29
26
  end
30
27
  end
31
28
 
@@ -49,16 +46,10 @@ class Bridgetown::Site
49
46
  matches
50
47
  end
51
48
 
52
- # Renders all documents
49
+ # Renders all resources
53
50
  # @return [void]
54
- def render_docs
51
+ def render_resources
55
52
  collections.each_value do |collection|
56
- collection.docs.each do |document|
57
- render_with_locale(document) do
58
- render_regenerated document
59
- end
60
- end
61
-
62
53
  collection.resources.each do |resource|
63
54
  render_with_locale(resource) do
64
55
  resource.transform!
@@ -67,22 +58,22 @@ class Bridgetown::Site
67
58
  end
68
59
  end
69
60
 
70
- # Renders all pages
61
+ # Renders all generated pages
71
62
  # @return [void]
72
- def render_pages
73
- pages.each do |page|
74
- render_regenerated page
63
+ def render_generated_pages
64
+ generated_pages.each do |page|
65
+ render_page page
75
66
  end
76
67
  end
77
68
 
78
- # Renders a document while ensuring site locale is set if the data is available.
79
- # @param document [Document] The document to render
69
+ # Renders a content item while ensuring site locale is set if the data is available.
70
+ # @param item [Document, Page, Bridgetown::Resource::Base] The item to render
80
71
  # @yield Runs the block in between locale setting and resetting
81
72
  # @return [void]
82
- def render_with_locale(document)
83
- if document.data["locale"]
73
+ def render_with_locale(item)
74
+ if item.data["locale"]
84
75
  previous_locale = locale
85
- self.locale = document.data["locale"]
76
+ self.locale = item.data["locale"]
86
77
  yield
87
78
  self.locale = previous_locale
88
79
  else
@@ -90,13 +81,11 @@ class Bridgetown::Site
90
81
  end
91
82
  end
92
83
 
93
- # Regenerates a site using {Renderer}
94
- # @param document [Document] The document to regenerate.
84
+ # Regenerates a content item using {Renderer}
85
+ # @param item [Page] The page to render
95
86
  # @return [void]
96
- def render_regenerated(document)
97
- return unless regenerator.regenerate?(document)
98
-
99
- Bridgetown::Renderer.new(self, document).run
87
+ def render_page(page)
88
+ Bridgetown::Renderer.new(self, page).run
100
89
  end
101
90
  end
102
91
  end
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Bridgetown::Site
4
+ module SSR
5
+ def self.included(base)
6
+ base.extend ClassMethods
7
+ end
8
+
9
+ module ClassMethods
10
+ # Establish an SSR pipeline for a persistent backend process
11
+ def start_ssr!
12
+ if Bridgetown::Current.site
13
+ raise Bridgetown::Errors::FatalException, "Bridgetown SSR already started! " \
14
+ "Check your Rack app for threading issues"
15
+ end
16
+
17
+ Bridgetown::PluginManager.require_from_bundler
18
+ site = new(Bridgetown::Current.preloaded_configuration)
19
+ site.enable_ssr
20
+
21
+ Bridgetown::Hooks.trigger :site, :pre_read, site
22
+ site.defaults_reader.tap do |d|
23
+ d.path_defaults.clear
24
+ d.read
25
+ end
26
+ site.layouts = Bridgetown::LayoutReader.new(site).read
27
+ site.collections.data.tap do |coll|
28
+ coll.read
29
+ site.data = coll.merge_data_resources
30
+ end
31
+ Bridgetown::Hooks.trigger :site, :post_read, site
32
+
33
+ yield(site) if block_given? # provide additional setup hook
34
+
35
+ site
36
+ end
37
+ end
38
+
39
+ def ssr?
40
+ @ssr_enabled == true
41
+ end
42
+
43
+ def enable_ssr
44
+ Bridgetown.logger.info "SSR:", "enabled."
45
+ @ssr_enabled = true
46
+ end
47
+
48
+ def disable_ssr
49
+ Bridgetown.logger.info "SSR:", "now disabled."
50
+ @ssr_enabled = false
51
+ end
52
+ end
53
+ end
@@ -13,21 +13,18 @@ class Bridgetown::Site
13
13
  #
14
14
  # @return [void]
15
15
  def write
16
- each_site_file do |item|
17
- item.write(dest) if regenerator.regenerate?(item)
18
- end
19
- regenerator.write_metadata
16
+ each_site_file { |item| item.write(dest) }
20
17
  Bridgetown::Hooks.trigger :site, :post_write, self
21
18
  end
22
19
 
23
- # Yields all content objects while looping through {#pages},
24
- # {#static_files_to_write}, {#docs_to_write}, {#resources_to_write}.
20
+ # Yields all content objects while looping through {#generated_pages},
21
+ # {#static_files_to_write}, {#resources_to_write}.
25
22
  #
26
- # @yieldparam item [Document, Page, StaticFile]
23
+ # @yieldparam item [Bridgetown::Resource::Base, GeneratedPage, StaticFile]
27
24
  #
28
25
  # @return [void]
29
26
  def each_site_file
30
- %w(pages static_files_to_write docs_to_write resources_to_write).each do |type|
27
+ %w(generated_pages static_files_to_write resources_to_write).each do |type|
31
28
  send(type).each do |item|
32
29
  yield item
33
30
  end