feat(faq): link siblings FAQs of same category
This commit is contained in:
parent
1e3c70feb8
commit
ae78224bac
5 changed files with 31 additions and 0 deletions
|
@ -7,6 +7,8 @@ class FAQController < ApplicationController
|
||||||
@renderer = Redcarpet::Markdown.new(
|
@renderer = Redcarpet::Markdown.new(
|
||||||
Redcarpet::BareRenderer.new(class_names_map: { list: 'fr-ol-content--override' })
|
Redcarpet::BareRenderer.new(class_names_map: { list: 'fr-ol-content--override' })
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@siblings = loader_service.faqs_for_category(@metadata[:category])
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
|
@ -16,6 +16,12 @@ class FAQsLoaderService
|
||||||
FrontMatterParser::Parser.parse_file(file_path)
|
FrontMatterParser::Parser.parse_file(file_path)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def faqs_for_category(category)
|
||||||
|
@faqs_by_path.values
|
||||||
|
.filter { |faq| faq[:category] == category }
|
||||||
|
.group_by { |faq| faq[:subcategory] }
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def load_faqs
|
def load_faqs
|
||||||
|
|
20
app/views/faq/_sidebar.html.haml
Normal file
20
app/views/faq/_sidebar.html.haml
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
%nav.fr-sidemenu.fr-sidemenu--sticky{ role: "navigation", 'aria-labelledby': "fr-sidemenu-title" }
|
||||||
|
.fr-sidemenu__inner
|
||||||
|
%button.fr-sidemenu__btn{ 'aria-controls': "fr-sidemenu-wrapper", 'aria-expanded': "false" }
|
||||||
|
= t(:sidebar_button, scope: [:faq])
|
||||||
|
.fr-collapse#fr-sidemenu-wrapper
|
||||||
|
.fr-sidemenu__title#fr-sidemenu-title
|
||||||
|
= t(:name, scope: [:faq, :categories, current[:category]])
|
||||||
|
%ul.fr-sidemenu__list
|
||||||
|
- faqs.each_with_index do |(subcategory, faqs), index|
|
||||||
|
%li{ class: class_names("fr-sidemenu__item", "fr-sidemenu__item--active" => subcategory == current[:subcategory]) }
|
||||||
|
%button.fr-sidemenu__btn{ aria: { 'expanded': subcategory == current[:subcategory] ? "true" : "false",
|
||||||
|
'controls': "fr-sidemenu-item-#{index}",
|
||||||
|
'current' => subcategory == current[:subcategory] ? "true" : nil } }
|
||||||
|
= t(:name, scope: [:faq, :subcategories, subcategory])
|
||||||
|
.fr-collapse{ id: "fr-sidemenu-item-#{index}" }
|
||||||
|
%ul.fr-sidemenu__list
|
||||||
|
- faqs.each do |faq|
|
||||||
|
%li{ class: class_names("fr-sidemenu__item", "fr-sidemenu__item--active" => faq[:slug] == current[:slug]) }
|
||||||
|
= link_to faq[:title], faq_path(category: faq[:category], slug: faq[:slug]),
|
||||||
|
class: 'fr-sidemenu__link', target: "_self", "aria-current" => current[:slug] == faq[:slug] ? "page" : nil
|
|
@ -2,5 +2,7 @@
|
||||||
|
|
||||||
.fr-container.fr-my-4w
|
.fr-container.fr-my-4w
|
||||||
.fr-grid-row
|
.fr-grid-row
|
||||||
|
.fr-col-12.fr-col-md-4
|
||||||
|
= render partial: "sidebar", locals: { faqs: @siblings, current: @metadata }
|
||||||
.fr-col-12.fr-col-md-8.fr-py-12v
|
.fr-col-12.fr-col-md-8.fr-py-12v
|
||||||
= @renderer.render(@content).html_safe
|
= @renderer.render(@content).html_safe
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
fr:
|
fr:
|
||||||
faq:
|
faq:
|
||||||
|
sidebar_button: Dans cette Foire Aux Questions
|
||||||
categories:
|
categories:
|
||||||
usager:
|
usager:
|
||||||
name: Usager (dépôt d’un dossier)
|
name: Usager (dépôt d’un dossier)
|
||||||
|
|
Loading…
Reference in a new issue