bridgetown-core 0.21.4 → 1.0.0.alpha1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (101) 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 +6 -117
  18. data/lib/bridgetown-core/concerns/site/localizable.rb +3 -1
  19. data/lib/bridgetown-core/concerns/site/processable.rb +8 -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/filters/url_filters.rb +3 -1
  34. data/lib/bridgetown-core/frontmatter_defaults.rb +44 -80
  35. data/lib/bridgetown-core/{page.rb → generated_page.rb} +34 -58
  36. data/lib/bridgetown-core/generators/prototype_generator.rb +10 -21
  37. data/lib/bridgetown-core/helpers.rb +7 -2
  38. data/lib/bridgetown-core/layout.rb +15 -4
  39. data/lib/bridgetown-core/log_writer.rb +6 -0
  40. data/lib/bridgetown-core/model/base.rb +10 -2
  41. data/lib/bridgetown-core/model/builder_origin.rb +22 -10
  42. data/lib/bridgetown-core/model/origin.rb +3 -0
  43. data/lib/bridgetown-core/model/plugin_origin.rb +34 -0
  44. data/lib/bridgetown-core/model/repo_origin.rb +1 -1
  45. data/lib/bridgetown-core/plugin_manager.rb +8 -8
  46. data/lib/bridgetown-core/rack/boot.rb +47 -0
  47. data/lib/bridgetown-core/rack/logger.rb +22 -0
  48. data/lib/bridgetown-core/rack/roda.rb +66 -0
  49. data/lib/bridgetown-core/rack/routes.rb +92 -0
  50. data/lib/bridgetown-core/rack/static_indexes.rb +30 -0
  51. data/lib/bridgetown-core/reader.rb +16 -48
  52. data/lib/bridgetown-core/readers/plugin_content_reader.rb +8 -7
  53. data/lib/bridgetown-core/renderer.rb +1 -11
  54. data/lib/bridgetown-core/resource/base.rb +33 -10
  55. data/lib/bridgetown-core/resource/permalink_processor.rb +20 -10
  56. data/lib/bridgetown-core/resource/relations.rb +2 -3
  57. data/lib/bridgetown-core/resource/transformer.rb +1 -1
  58. data/lib/bridgetown-core/ruby_template_view.rb +5 -5
  59. data/lib/bridgetown-core/site.rb +4 -8
  60. data/lib/bridgetown-core/static_file.rb +10 -15
  61. data/lib/bridgetown-core/tags/include.rb +0 -13
  62. data/lib/bridgetown-core/tags/link.rb +4 -0
  63. data/lib/bridgetown-core/tags/live_reload_dev_js.rb +13 -0
  64. data/lib/bridgetown-core/tags/post_url.rb +4 -9
  65. data/lib/bridgetown-core/tasks/bridgetown_tasks.rake +54 -0
  66. data/lib/bridgetown-core/url.rb +2 -1
  67. data/lib/bridgetown-core/utils/aux.rb +57 -0
  68. data/lib/bridgetown-core/utils/ruby_exec.rb +3 -45
  69. data/lib/bridgetown-core/utils/ruby_front_matter.rb +22 -7
  70. data/lib/bridgetown-core/utils.rb +37 -2
  71. data/lib/bridgetown-core/version.rb +2 -2
  72. data/lib/bridgetown-core/watcher.rb +2 -4
  73. data/lib/bridgetown-core.rb +14 -22
  74. data/lib/site_template/Gemfile.erb +6 -2
  75. data/lib/site_template/README.md +6 -6
  76. data/lib/site_template/Rakefile +49 -0
  77. data/lib/site_template/bridgetown.config.yml +2 -3
  78. data/lib/site_template/config/puma.rb +27 -0
  79. data/lib/site_template/config.ru +7 -0
  80. data/lib/site_template/package.json.erb +1 -9
  81. data/lib/site_template/server/roda_app.rb +22 -0
  82. data/lib/site_template/server/routes/hello.rb.sample +10 -0
  83. data/lib/site_template/src/_components/head.liquid +2 -1
  84. data/lib/site_template/src/about.md +0 -1
  85. data/lib/site_template/src/posts.md +2 -3
  86. metadata +62 -18
  87. data/lib/bridgetown-core/concerns/data_accessible.rb +0 -20
  88. data/lib/bridgetown-core/concerns/validatable.rb +0 -56
  89. data/lib/bridgetown-core/document.rb +0 -437
  90. data/lib/bridgetown-core/drops/document_drop.rb +0 -80
  91. data/lib/bridgetown-core/drops/excerpt_drop.rb +0 -19
  92. data/lib/bridgetown-core/drops/page_drop.rb +0 -18
  93. data/lib/bridgetown-core/excerpt.rb +0 -200
  94. data/lib/bridgetown-core/readers/data_reader.rb +0 -89
  95. data/lib/bridgetown-core/readers/page_reader.rb +0 -26
  96. data/lib/bridgetown-core/readers/post_reader.rb +0 -109
  97. data/lib/bridgetown-core/regenerator.rb +0 -202
  98. data/lib/bridgetown-core/related_posts.rb +0 -55
  99. data/lib/site_template/config/.keep +0 -0
  100. data/lib/site_template/start.js +0 -17
  101. 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,15 +106,6 @@ 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
@@ -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,20 +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
38
+ self.data = HashWithDotAccess::Hash.new unless soft
37
39
  @frontend_manifest = nil
38
- @post_attr_hash = {}
39
40
  @collections = nil
40
41
  @documents = nil
41
42
  @docs_to_write = nil
42
- @regenerator.clear_cache
43
43
  @liquid_renderer.reset
44
- frontmatter_defaults.reset
44
+ frontmatter_defaults.reset unless soft
45
45
 
46
- Bridgetown::Cache.clear_if_config_changed config
47
- 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
48
48
  end
49
49
 
50
50
  # Read data from disk and load it into internal memory.
@@ -52,23 +52,11 @@ class Bridgetown::Site
52
52
  def read
53
53
  Bridgetown::Hooks.trigger :site, :pre_read, self
54
54
  reader.read
55
- limit_posts!
56
55
  Bridgetown::Hooks.trigger :site, :post_read, self
57
56
  end
58
57
 
59
58
  private
60
59
 
61
- # Limits the current posts; removes the posts which exceed the limit_posts
62
- def limit_posts!
63
- if config.limit_posts.positive?
64
- Bridgetown::Deprecator.deprecation_message(
65
- "The limit_posts config option will be removed prior to Bridgetown 1.0"
66
- )
67
- limit = posts.docs.length < config.limit_posts ? posts.docs.length : config.limit_posts
68
- posts.docs = posts.docs[-limit, limit]
69
- end
70
- end
71
-
72
60
  def print_stats
73
61
  Bridgetown.logger.info @liquid_renderer.stats_table
74
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
@@ -34,32 +34,28 @@ module Bridgetown
34
34
  "encoding" => "utf-8",
35
35
  "markdown_ext" => "markdown,mkdown,mkdn,mkd,md",
36
36
  "strict_front_matter" => false,
37
- "slugify_categories" => true,
38
37
  "slugify_mode" => "pretty",
39
38
 
40
39
  # Filtering Content
41
- "limit_posts" => 0,
42
40
  "future" => false,
43
41
  "unpublished" => false,
44
42
  "ruby_in_front_matter" => true,
45
43
 
46
44
  # Conversion
45
+ "content_engine" => "resource",
47
46
  "markdown" => "kramdown",
48
47
  "highlighter" => "rouge",
49
- "lsi" => false,
50
48
  "excerpt_separator" => "\n\n",
51
- "incremental" => false,
52
49
 
53
50
  # Serving
54
- "detach" => false, # default to not detaching the server
55
51
  "port" => "4000",
56
52
  "host" => "127.0.0.1",
57
53
  "base_path" => "/",
58
54
  "show_dir_listing" => false,
59
55
 
60
56
  # Output Configuration
61
- "available_locales" => ["en"],
62
- "default_locale" => "en",
57
+ "available_locales" => [:en],
58
+ "default_locale" => :en,
63
59
  "permalink" => nil, # default is set according to content engine
64
60
  "timezone" => nil, # use the local timezone
65
61
 
@@ -103,6 +99,7 @@ module Bridgetown
103
99
  def from(user_config, starting_defaults = DEFAULTS)
104
100
  Utils.deep_merge_hashes(starting_defaults.deep_dup, Configuration[user_config])
105
101
  .merge_environment_specific_options!
102
+ .setup_locales
106
103
  .add_default_collections
107
104
  .add_default_excludes
108
105
  .check_include_exclude
@@ -247,6 +244,12 @@ module Bridgetown
247
244
  self
248
245
  end
249
246
 
247
+ def setup_locales
248
+ self.default_locale = default_locale.to_sym
249
+ available_locales.map!(&:to_sym)
250
+ self
251
+ end
252
+
250
253
  def add_default_collections # rubocop:todo all
251
254
  # It defaults to `{}`, so this is only if someone sets it to null manually.
252
255
  return self if self[:collections].nil?
@@ -263,23 +266,16 @@ module Bridgetown
263
266
  self[:collections][:posts][:output] = true
264
267
  self[:collections][:posts][:sort_direction] ||= "descending"
265
268
 
266
- if self[:content_engine] == "resource"
267
- self[:permalink] = "pretty" if self[:permalink].blank?
268
- self[:collections][:pages] = {} unless self[:collections][:pages]
269
- self[:collections][:pages][:output] = true
270
- self[:collections][:pages][:permalink] ||= "/:path/"
269
+ self[:permalink] = "pretty" if self[:permalink].blank?
270
+ self[:collections][:pages] = {} unless self[:collections][:pages]
271
+ self[:collections][:pages][:output] = true
272
+ self[:collections][:pages][:permalink] ||= "/:locale/:path/"
271
273
 
272
- self[:collections][:data] = {} unless self[:collections][:data]
273
- self[:collections][:data][:output] = false
274
+ self[:collections][:data] = {} unless self[:collections][:data]
275
+ self[:collections][:data][:output] = false
274
276
 
275
- unless self[:collections][:posts][:permalink]
276
- self[:collections][:posts][:permalink] = self[:permalink]
277
- end
278
- else
279
- self[:permalink] = "date" if self[:permalink].blank?
280
- unless self[:collections][:posts][:permalink]
281
- self[:collections][:posts][:permalink] = style_to_permalink(self[:permalink])
282
- end
277
+ unless self[:collections][:posts][:permalink]
278
+ self[:collections][:posts][:permalink] = self[:permalink]
283
279
  end
284
280
 
285
281
  self
@@ -304,26 +300,6 @@ module Bridgetown
304
300
  self["ruby_in_front_matter"]
305
301
  end
306
302
 
307
- # Deprecated, to be removed when Bridgetown goes Resource-only
308
- def style_to_permalink(permalink_style) # rubocop:todo Metrics/CyclomaticComplexity
309
- case permalink_style.to_s.to_sym
310
- when :pretty
311
- "/:categories/:year/:month/:day/:title/"
312
- when :simple
313
- "/:categories/:title/"
314
- when :none
315
- "/:categories/:title:output_ext"
316
- when :date
317
- "/:categories/:year/:month/:day/:title:output_ext"
318
- when :ordinal
319
- "/:categories/:year/:y_day/:title:output_ext"
320
- when :weekdate
321
- "/:categories/:year/W:week/:short_day/:title:output_ext"
322
- else
323
- permalink_style.to_s
324
- end
325
- end
326
-
327
303
  def check_include_exclude
328
304
  %w(include exclude).each do |option|
329
305
  next unless key?(option)
@@ -333,11 +309,6 @@ module Bridgetown
333
309
  "'#{option}' should be set as an array, but was: #{self[option].inspect}."
334
310
  end
335
311
 
336
- unless self[:include].include?("_pages") || self[:content_engine] == "resource"
337
- # add _pages to includes set
338
- self[:include] << "_pages"
339
- end
340
-
341
312
  self
342
313
  end
343
314