2022-09-07 06:52:24 +00:00
|
|
|
class Public::Api::V1::Portals::ArticlesController < PublicController
|
|
|
|
before_action :ensure_custom_domain_request, only: [:show, :index]
|
2022-09-20 00:36:01 +00:00
|
|
|
before_action :portal
|
2022-09-07 06:52:24 +00:00
|
|
|
before_action :set_category
|
2022-07-08 11:54:38 +00:00
|
|
|
before_action :set_article, only: [:show]
|
2022-09-12 18:06:24 +00:00
|
|
|
layout 'portal'
|
2022-07-08 11:54:38 +00:00
|
|
|
|
|
|
|
def index
|
|
|
|
@articles = @portal.articles
|
2022-07-28 08:29:16 +00:00
|
|
|
@articles = @articles.search(list_params) if list_params.present?
|
2022-07-08 11:54:38 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def show; end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def set_article
|
2022-09-07 06:52:24 +00:00
|
|
|
@article = @category.articles.find(params[:id])
|
2022-09-12 18:06:24 +00:00
|
|
|
@parsed_content = render_article_content(@article.content)
|
2022-09-07 06:52:24 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def set_category
|
|
|
|
@category = @portal.categories.find_by!(slug: params[:category_slug])
|
2022-07-08 11:54:38 +00:00
|
|
|
end
|
|
|
|
|
2022-09-20 00:36:01 +00:00
|
|
|
def portal
|
|
|
|
@portal ||= Portal.find_by!(slug: params[:slug], archived: false)
|
2022-07-08 11:54:38 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def list_params
|
2022-07-28 08:29:16 +00:00
|
|
|
params.permit(:query)
|
2022-07-08 11:54:38 +00:00
|
|
|
end
|
2022-09-12 18:06:24 +00:00
|
|
|
|
|
|
|
def render_article_content(content)
|
|
|
|
# rubocop:disable Rails/OutputSafety
|
|
|
|
CommonMarker.render_html(content).html_safe
|
|
|
|
# rubocop:enable Rails/OutputSafety
|
|
|
|
end
|
2022-07-08 11:54:38 +00:00
|
|
|
end
|