Module: Bridgetown::Site::SSR
- Included in:
- Bridgetown::Site
- Defined in:
- bridgetown-core/lib/bridgetown-core/concerns/site/ssr.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
-
#disable_ssr ⇒ Object
-
#enable_ssr ⇒ Object
-
#ssr? ⇒ Boolean
-
#ssr_first_read ⇒ Object
-
#ssr_setup(&block) ⇒ Object
Class Method Details
.included(base) ⇒ Object
5 6 7 |
# File 'bridgetown-core/lib/bridgetown-core/concerns/site/ssr.rb', line 5 def self.included(base) base.extend ClassMethods end |
Instance Method Details
#disable_ssr ⇒ Object
68 69 70 71 |
# File 'bridgetown-core/lib/bridgetown-core/concerns/site/ssr.rb', line 68 def disable_ssr Bridgetown.logger.info "SSR:", "now disabled." @ssr_enabled = false end |
#enable_ssr ⇒ Object
29 30 31 32 33 |
# File 'bridgetown-core/lib/bridgetown-core/concerns/site/ssr.rb', line 29 def enable_ssr Bridgetown.logger.info "SSR:", "enabled." config.fast_refresh = false # SSR mode and Fast Refresh mode are mututally exclusive @ssr_enabled = true end |
#ssr? ⇒ Boolean
25 26 27 |
# File 'bridgetown-core/lib/bridgetown-core/concerns/site/ssr.rb', line 25 def ssr? @ssr_enabled == true end |
#ssr_first_read ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'bridgetown-core/lib/bridgetown-core/concerns/site/ssr.rb', line 47 def ssr_first_read # TODO: this shouldn't be running twice, right?! Bridgetown::Hooks.trigger :site, :pre_read, self defaults_reader.tap do |d| d.path_defaults.clear d.read end reader.read_layouts collections.data.tap do |coll| coll.read self.data = coll.merge_data_resources end # This part is handled via a hook so it is supported by the SSR "soft reset" Bridgetown::Hooks.register_one :site, :post_read, reloadable: false, priority: :high do reader.read_directories reader.sort_files! reader.read_collections end end |
#ssr_setup(&block) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 |
# File 'bridgetown-core/lib/bridgetown-core/concerns/site/ssr.rb', line 35 def ssr_setup(&block) Bridgetown::Hooks.trigger :site, :pre_read, self ssr_first_read Bridgetown::Hooks.trigger :site, :post_read, self block&.call(self) # provide additional setup hook return if Bridgetown.env.production? Bridgetown::Watcher.watch(self, config, &block) end |