diff --git a/app/controllers/internal/pages_controller.rb b/app/controllers/internal/pages_controller.rb index 2c9cabbe6..56a93163d 100644 --- a/app/controllers/internal/pages_controller.rb +++ b/app/controllers/internal/pages_controller.rb @@ -34,7 +34,7 @@ class Internal::PagesController < Internal::ApplicationController private def page_params - allowed_params = %i[title slug body_markdown body_html description template is_top_level_path social_image] + allowed_params = %i[title slug body_markdown body_html body_json description template is_top_level_path social_image] params.require(:page).permit(allowed_params) end end diff --git a/app/controllers/pages_controller.rb b/app/controllers/pages_controller.rb index 36fb9d682..7db3b9fab 100644 --- a/app/controllers/pages_controller.rb +++ b/app/controllers/pages_controller.rb @@ -7,6 +7,7 @@ class PagesController < ApplicationController not_found unless FeatureFlag.accessible?(@page.feature_flag_name, current_user) set_surrogate_key_header "show-page-#{params[:slug]}" + render json: @page.processed_html if @page.template == "json" end def about diff --git a/app/controllers/stories_controller.rb b/app/controllers/stories_controller.rb index aeaebab3c..d8b1d2b4f 100644 --- a/app/controllers/stories_controller.rb +++ b/app/controllers/stories_controller.rb @@ -157,7 +157,12 @@ class StoriesController < ApplicationController def handle_page_display @story_show = true set_surrogate_key_header "show-page-#{params[:username]}" - render template: "pages/show" + + if @page.template == "json" + render json: @page.processed_html + else + render template: "pages/show" + end end def handle_base_index diff --git a/app/models/page.rb b/app/models/page.rb index 9bddc3107..30ad96026 100644 --- a/app/models/page.rb +++ b/app/models/page.rb @@ -1,5 +1,5 @@ class Page < ApplicationRecord - TEMPLATE_OPTIONS = %w[contained full_within_layout].freeze + TEMPLATE_OPTIONS = %w[contained full_within_layout json].freeze validates :title, presence: true validates :description, presence: true @@ -38,7 +38,7 @@ class Page < ApplicationRecord end def body_present - errors.add(:body_markdown, "must exist if body_html doesn't exist.") if body_markdown.blank? && body_html.blank? + errors.add(:body_markdown, "must exist if body_html or body_json doesn't exist.") if body_markdown.blank? && body_html.blank? && body_json.blank? end def unique_slug_including_users_and_orgs diff --git a/app/views/internal/pages/_form.html.erb b/app/views/internal/pages/_form.html.erb index 085f5b57a..539f3d344 100644 --- a/app/views/internal/pages/_form.html.erb +++ b/app/views/internal/pages/_form.html.erb @@ -10,16 +10,25 @@ <%= form.text_field :slug, class: "form-control" %>
(Determines the way page's body will be embedded in the layout)
+json)
+ <%= form.text_area :body_json, class: "form-control" %>
(Determines the way page's body will be embedded in the layout)
-