feat(faq): list FAQs

This commit is contained in:
Colin Darie 2024-04-22 16:44:27 +02:00
parent ae78224bac
commit 08c237c028
No known key found for this signature in database
GPG key ID: 4FB865FDBCA4BCC4
5 changed files with 43 additions and 0 deletions

View file

@ -3,6 +3,10 @@
class FAQController < ApplicationController
before_action :load_faq_data, only: :show
def index
@faqs = loader_service.all
end
def show
@renderer = Redcarpet::Markdown.new(
Redcarpet::BareRenderer.new(class_names_map: { list: 'fr-ol-content--override' })

View file

@ -22,6 +22,16 @@ class FAQsLoaderService
.group_by { |faq| faq[:subcategory] }
end
def all
@faqs_by_path.values
.group_by { |faq| faq.fetch(:category) }
.sort_by { |category, _| ORDER.index(category) || ORDER.size }
.to_h
.transform_values do |faqs|
faqs.group_by { |faq| faq.fetch(:subcategory) }
end
end
private
def load_faqs

View file

@ -0,0 +1,25 @@
- content_for(:title, t('.meta_title'))
.fr-container.fr-my-4w
.fr-grid-row
.fr-col-12.fr-col-md-10
%h1= t('.title', app_name: Current.application_name)
- @faqs.each do |category, subcategories|
%h2= t(:name, scope: [:faq, :categories, category], raise: true)
%p= t(:description, scope: [:faq, :categories, category], raise: true)
.fr-accordions-group.fr-mb-6w
- subcategories.each_with_index do |(subcategory, faqs), index|
%section.fr-accordion
%h3.fr-accordion__title
%button.fr-accordion__btn{ 'aria-expanded': "false", 'aria-controls': "accordion-#{category}-#{index}" }
= t(:name, scope: [:faq, :subcategories, subcategory], raise: true)
.fr-collapse{ id: "accordion-#{category}-#{index}" }
- description = t(:description, scope: [:faq, :subcategories, subcategory], default: nil)
%p= description if description.present?
%ul
- faqs.each do |faq|
%li= link_to faq[:title], faq_path(category: faq[:category], slug: faq[:slug]), class: "fr-link"

View file

@ -1,5 +1,8 @@
fr:
faq:
index:
meta_title: "Foire aux Questions"
title: Foire aux Questions (FAQ) de %{app_name}
sidebar_button: Dans cette Foire Aux Questions
categories:
usager:

View file

@ -715,6 +715,7 @@ Rails.application.routes.draw do
resources :release_notes, only: [:index]
resources :faq, only: [:index]
get '/faq/:category/:slug', to: 'faq#show', as: :faq
get '/404', to: 'errors#not_found'