@@ -17,22 +17,22 @@ const categoryParents = _.lodash.groupBy(allCategories, ({ parent }) => {
1717 return ! parent || ! parent .slug ? ' _' : parent .slug
1818})
1919const getSubmenuId = slug => ` a-${ slug .replace (/ \/ / g , ' _' )} `
20- const mainCategories = categoryParents ._
21- if (mainCategories) {
22- if (Array .isArray (menu .sort_categories )) {
23- // reorder first level categories list
24- for (let i = menu .sort_categories .length - 1 ; i >= 0 ; i-- ) {
25- const slug = menu .sort_categories [i]
26- const categoryIndex = mainCategories .findIndex (category => category .slug === slug)
27- if (categoryIndex > - 1 ) {
28- const category = mainCategories[categoryIndex]
29- mainCategories .splice (categoryIndex, 1 )
30- mainCategories .unshift (category)
31- }
32- }
33- }
34- }
20+ const mainCategories = categoryParents ._ || []
21+
22+ // helper para pegar categoria pelo slug
23+ const bySlug = slug => mainCategories .find (cat => cat .slug === slug)
24+ const catAprenda = bySlug (' aprenda-se-divertindo' )
25+ const catColecoes = bySlug (' colecoes' )
26+ const catParceiros = bySlug (' parceiros' )
27+
28+ // filhos / netos das 3 categorias especiais
29+ const childrenAprenda = catAprenda ? (categoryParents[catAprenda .slug ] || []) : []
30+ const childrenColecoes = catColecoes ? (categoryParents[catColecoes .slug ] || []) : []
31+ const childrenParceiros = catParceiros ? (categoryParents[catParceiros .slug ] || []) : []
32+
33+ const getGrandChildren = (cat ) => categoryParents[cat .slug ] || []
3534%>
35+
3636<aside id =" menu" class =" menu shadow" >
3737 <nav class =" accordion" id =" accordion-menu" >
3838 <button
@@ -44,70 +44,61 @@ if (mainCategories) {
4444 <i class =" i-times" ></i >
4545 </button >
4646
47- <% if (mainCategories && mainCategories . length ) { % >
48- < div
49- id = " categories-nav "
50- class = " collapse show "
51- aria - expanded = " true "
52- data - parent = " #accordion-menu "
53- >
54- < div class = " menu__list " >
55- < % mainCategories . forEach ( parent => { % >
56- < % const children = categoryParents[ parent . slug ] || [] % >
47+ <div
48+ id = " categories-nav "
49+ class = " collapse show "
50+ aria-expanded = " true "
51+ data-parent = " #accordion-menu "
52+ >
53+ < div class = " menu__list " >
54+ <!-- mantém exatamente as categorias do topo -- >
55+ < a href = " /camiseta " class = " menu__item " >Camisetas</ a >
56+ < a href = " /camisetas-infantis " class = " menu__item " >Camisetas Infantis</ a >
5757
58- < % if (children .length ) { % >
59- <!-- Categoria de primeiro nível com subcategorias -->
60- < button
61- class = " menu__item menu__item--toggle"
62- type= " button"
63- data- toggle= " collapse"
64- data- target= " #<%= getSubmenuId(parent.slug) %>"
65- aria- expanded= " false"
66- >
67- < %= parent .name % >
68- < / button>
58+ <!-- Aprenda se Divertindo + filhos/netos -->
59+ <a href =" /aprenda-se-divertindo" class =" menu__item" >Aprenda se Divertindo</a >
60+ <% childrenAprenda .forEach (child => { % >
61+ < a href= " /<%= child.slug %>" class = " menu__item menu__item--sub" >
62+ < %= child .name % >
63+ < / a>
64+ < % getGrandChildren (child).forEach (grand => { % >
65+ < a href= " /<%= grand.slug %>" class = " menu__item menu__item--sub2" >
66+ < %= grand .name % >
67+ < / a>
68+ < % }) % >
69+ < % }) %>
6970
70- < div
71- id= " <%= getSubmenuId(parent.slug) %>"
72- class = " collapse menu__submenu"
73- data- parent= " #categories-nav"
74- >
75- < % children .forEach (child => { % >
76- < % const grandChildren = categoryParents[child .slug ] || [] % >
71+ <a href =" /estampas" class =" menu__item" >Estampas</a >
7772
78- < a
79- href= " /<%= child.slug %>"
80- class = " menu__item menu__item--sub"
81- >
82- < %= child .name % >
83- < / a>
73+ <!-- Coleções + filhos/netos -->
74+ <a href =" /colecoes" class =" menu__item" >Coleções</a >
75+ <% childrenColecoes .forEach (child => { % >
76+ < a href= " /<%= child.slug %>" class = " menu__item menu__item--sub" >
77+ < %= child .name % >
78+ < / a>
79+ < % getGrandChildren (child).forEach (grand => { % >
80+ < a href= " /<%= grand.slug %>" class = " menu__item menu__item--sub2" >
81+ < %= grand .name % >
82+ < / a>
83+ < % }) % >
84+ < % }) %>
8485
85- < % if (grandChildren .length ) { % >
86- < % grandChildren .forEach (grandChild => { % >
87- < a
88- href= " /<%= grandChild.slug %>"
89- class = " menu__item menu__item--sub2"
90- >
91- < %= grandChild .name % >
92- < / a>
93- < % }) % >
94- < % } % >
95- < % }) % >
96- < / div>
97- < % } else { % >
98- <!-- Categoria de primeiro nível sem filhos -->
99- < a
100- href= " /<%= parent.slug %>"
101- class = " menu__item"
102- >
103- < %= parent .name % >
104- < / a>
105- < % } % >
86+ <!-- Parceiros + filhos/netos -->
87+ <a href =" /parceiros" class =" menu__item" >Parceiros</a >
88+ <% childrenParceiros .forEach (child => { % >
89+ < a href= " /<%= child.slug %>" class = " menu__item menu__item--sub" >
90+ < %= child .name % >
91+ < / a>
92+ < % getGrandChildren (child).forEach (grand => { % >
93+ < a href= " /<%= grand.slug %>" class = " menu__item menu__item--sub2" >
94+ < %= grand .name % >
95+ < / a>
10696 < % }) % >
107- < / div >
97+ < % }) % >
10898 </div >
109- < % } % >
99+ </ div >
110100 </nav >
101+
111102 <footer class =" menu__footer" >
112103 <% if (menu .phone_wpp ) { % >
113104 < div class = " menu__phone" >
0 commit comments