Sha256: bda93b461cdd9ebb9c812efd65f728665345ba51ad2ac13b6c410dce34237031

Contents?: true

Size: 1.09 KB

Versions: 15

Compression:

Stored size: 1.09 KB

Contents

# frozen_string_literal: true

module Maglev
  module RenderingConcern
    extend ActiveSupport::Concern

    included do
      include Maglev::FetchersConcern
    end

    private

    def render_maglev_page
      raise ActionController::UnknownFormat, 'Maglev renders HTML pages only' if request.format != 'html'

      fetch_maglev_page_content

      verify_canonical_path and return

      render template: fetch_maglev_theme_layout, layout: false
    end

    def verify_canonical_path
      # the section mode is only used to display the content of a single section
      # in the admin UI.
      return if maglev_rendering_mode == :section

      # check if we're processing the right version (canonical) of the page
      # if not, follow the proper SEO rule by redirecting the user with a 301
      canonical_path = maglev_page.path

      return false if !canonical_path || params[:path] == canonical_path

      next_path = maglev_rendering_mode == :editor ? site_preview_path(path: canonical_path) : "/#{canonical_path}"
      redirect_to next_path, status: :moved_permanently

      true
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
maglevcms-1.2.2 app/controllers/concerns/maglev/rendering_concern.rb
maglevcms-1.2.1 app/controllers/concerns/maglev/rendering_concern.rb
maglevcms-1.2.0 app/controllers/concerns/maglev/rendering_concern.rb
maglevcms-1.1.7 app/controllers/concerns/maglev/rendering_concern.rb
maglevcms-1.1.6 app/controllers/concerns/maglev/rendering_concern.rb
maglevcms-1.1.5 app/controllers/concerns/maglev/rendering_concern.rb
maglevcms-1.1.4 app/controllers/concerns/maglev/rendering_concern.rb
maglevcms-1.1.3 app/controllers/concerns/maglev/rendering_concern.rb
maglevcms-1.1.2 app/controllers/concerns/maglev/rendering_concern.rb
maglevcms-1.1.1 app/controllers/concerns/maglev/rendering_concern.rb
maglevcms-1.1.0 app/controllers/concerns/maglev/rendering_concern.rb
maglevcms-1.0.0 app/controllers/concerns/maglev/rendering_concern.rb
maglevcms-1.0.0.rc3 app/controllers/concerns/maglev/rendering_concern.rb
maglevcms-1.0.0.rc2 app/controllers/concerns/maglev/rendering_concern.rb
maglevcms-1.0.0.rc1 app/controllers/concerns/maglev/rendering_concern.rb