class PagesController < ApplicationController
  append_view_path "pages"
  layout :layout_by_path

  def show
    @page = Page.new(view_context, params[:path])

    # If the page doesn't exist, throw a 404
    raise ActionController::RoutingError.new("The documentation page `#{@page.basename}` does not exist") unless @page.exists?

    # For the homepage, render with a custom layout that doesn't include the sidebar etc

    # If there's another more correct version of the URL (for example, we changed `_`
    # to `-`), then redirect them to where they should be.
    unless @page.is_canonical?
      redirect_to "/docs/#{@page.canonical_url}", status: :moved_permanently
    end

    # Otherwise, render the page (the default)
  end

  private

  def beta?
    @page && @page.beta?
  end
  helper_method :beta?

  def is_landing_page?
    @page && @page.is_landing_page?
  end
  helper_method :is_landing_page?

  def layout_by_path
    if request.path == "/docs"
      "homepage"
    elsif request.path.starts_with? "/docs/apis/graphql"
      "graphql"
    else
      "application"
    end
  end
end

class PagesController < ApplicationController
  append_view_path "pages"
  layout :layout_by_path

  def index
    render :index, layout: "homepage"
  end

  def show
    @page = Page.new(view_context, params[:path])

    # If the page doesn't exist, throw a 404
    raise ActionController::RoutingError.new("The documentation page `#{@page.basename}` does not exist") unless @page.exists?

    # If there's another more correct version of the URL (for example, we changed `_`
    # to `-`), then redirect them to where they should be.
    unless @page.is_canonical?
      redirect_to "/docs/#{@page.canonical_url}", status: :moved_permanently
    end

    # Otherwise, render the page (the default)
  end

  private

  def beta?
    @page && @page.beta?
  end
  helper_method :beta?

  def is_landing_page?
    @page && @page.is_landing_page?
  end
  helper_method :is_landing_page?

  def layout_by_path
    if request.path.starts_with? "/docs/apis/graphql"
      "graphql"
    else
      "application"
    end
  end
end

Define index action for homepage
Define index action for homepage

- To remove the confusion of where the home page is defined,
  making it easier to understand what is happening
- Also removing one branch in the layout conditional
