Sha256: 7a8c479f5768a14041425d951e37c18ddcdb007b43cf7fb72623fbc40fc94d1b

Contents?: true

Size: 1.37 KB

Versions: 1

Compression:

Stored size: 1.37 KB

Contents

# frozen_string_literal: true

class Bridgetown::Site
  module SSR
    def self.included(base)
      base.extend ClassMethods
    end

    module ClassMethods
      # Establish an SSR pipeline for a persistent backend process
      def start_ssr!
        if Bridgetown::Current.site
          raise Bridgetown::Errors::FatalException, "Bridgetown SSR already started! " \
                                                    "Check your Rack app for threading issues"
        end

        Bridgetown::PluginManager.require_from_bundler
        site = new(Bridgetown::Current.preloaded_configuration)
        site.enable_ssr

        Bridgetown::Hooks.trigger :site, :pre_read, site
        site.defaults_reader.tap do |d|
          d.path_defaults.clear
          d.read
        end
        site.layouts = Bridgetown::LayoutReader.new(site).read
        site.collections.data.tap do |coll|
          coll.read
          site.data = coll.merge_data_resources
        end
        Bridgetown::Hooks.trigger :site, :post_read, site

        yield(site) if block_given? # provide additional setup hook

        site
      end
    end

    def ssr?
      @ssr_enabled == true
    end

    def enable_ssr
      Bridgetown.logger.info "SSR:", "enabled."
      @ssr_enabled = true
    end

    def disable_ssr
      Bridgetown.logger.info "SSR:", "now disabled."
      @ssr_enabled = false
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
bridgetown-core-1.0.0.alpha1 lib/bridgetown-core/concerns/site/ssr.rb