Sha256: 245fb4c3ebaaef7b46481f60f54b519c063f700e9674f86604665b25ee0b083f

Contents?: true

Size: 1.04 KB

Versions: 1

Compression:

Stored size: 1.04 KB

Contents

module Harpiya
  class HomeController < Harpiya::StoreController
    include Harpiya::CacheHelper

    before_action :load_homepage, only: [:index]

    respond_to :html

    def index
      if @cms_home_page&.visible?
        @homepage = @cms_home_page
      elsif try_harpiya_current_user&.admin?
        @homepage = @cms_home_page
        @edit_mode = true
      end

      if http_cache_enabled?
        fresh_when etag: store_etag, last_modified: last_modified_index, public: true
      end
    end

    private

    def etag_index
      [
        store_etag,
        last_modified_index,
      ]
    end

    def last_modified_index
      page_last_modified = @cms_home_page&.maximum(:updated_at)&.utc if @cms_home_page.respond_to?(:maximum)
      current_store_last_modified =current_store.updated_at.utc

      [page_last_modified, current_store_last_modified].compact.max
    end

    def accurate_title
      @cms_home_page&.seo_title || super
    end

    def load_homepage
      @cms_home_page = current_store.homepage(I18n.locale)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
harpiya_frontend-4.3.0.alpha app/controllers/harpiya/home_controller.rb