1+ ---
2+ layout: page
3+ # All the Categories of posts
4+ ---
5+
6+ {% include lang.html %}
7+
8+ {% assign HEAD_PREFIX = 'h_' %}
9+ {% assign LIST_PREFIX = 'l_' %}
10+
11+ {% assign group_index = 0 %}
12+
13+ {% assign sort_categories = site.categories | sort %}
14+
15+ {% for category in sort_categories %}
16+ {% assign category_name = category | first %}
17+ {% assign posts_of_category = category | last %}
18+ {% assign first_post = posts_of_category | first %}
19+
20+ {% if category_name == first_post.categories[0] %}
21+ {% assign sub_categories = '' | split: '' %}
22+
23+ {% for post in posts_of_category %}
24+ {% assign second_category = post.categories[1] %}
25+ {% if second_category %}
26+ {% unless sub_categories contains second_category %}
27+ {% assign sub_categories = sub_categories | push: second_category %}
28+ {% endunless %}
29+ {% endif %}
30+ {% endfor %}
31+
32+ {% comment %} CUSTOM SORTING LOGIC START {% endcomment %}
33+ {% assign custom_order = site.sub_category_orders[category_name] %}
34+
35+ {% if custom_order %}
36+ {% assign sorted_subs = "" | split: "" %}
37+ {% comment %} 1. Add specific ones in order {% endcomment %}
38+ {% for ordered_name in custom_order %}
39+ {% if sub_categories contains ordered_name %}
40+ {% assign sorted_subs = sorted_subs | push: ordered_name %}
41+ {% endif %}
42+ {% endfor %}
43+ {% comment %} 2. Add anything else alphabetically {% endcomment %}
44+ {% assign remaining_subs = "" | split: "" %}
45+ {% for sub in sub_categories %}
46+ {% unless custom_order contains sub %}
47+ {% assign remaining_subs = remaining_subs | push: sub %}
48+ {% endunless %}
49+ {% endfor %}
50+ {% assign remaining_subs = remaining_subs | sort %}
51+ {% for sub in remaining_subs %}
52+ {% assign sorted_subs = sorted_subs | push: sub %}
53+ {% endfor %}
54+ {% assign sub_categories = sorted_subs %}
55+ {% else %}
56+ {% assign sub_categories = sub_categories | sort %}
57+ {% endif %}
58+ {% comment %} CUSTOM SORTING LOGIC END {% endcomment %}
59+
60+ {% assign sub_categories_size = sub_categories | size %}
61+
62+ < div class ="card categories ">
63+ < div
64+ id ="{{ HEAD_PREFIX }}{{ group_index }} "
65+ class ="card-header d-flex justify-content-between hide-border-bottom "
66+ >
67+ < span class ="ms-2 ">
68+ < i class ="far fa-folder{% if sub_categories_size > 0 %}-open{% endif %} fa-fw "> </ i >
69+
70+ {% capture _category_url %}/categories/{{ category_name | slugify | url_encode }}/{% endcapture %}
71+ < a href ="{{ _category_url | relative_url }} " class ="mx-2 "> {{ category_name }}</ a >
72+
73+ {% assign top_posts_size = site.categories[category_name] | size %}
74+ < span class ="text-muted small font-weight-light ">
75+ {% if sub_categories_size > 0 %}
76+ {{ sub_categories_size }}
77+ {% if sub_categories_size > 1 %}
78+ {{
79+ site.data.locales[lang].categories.category_measure.plural
80+ | default: site.data.locales[lang].categories.category_measure
81+ }}
82+ {% else %}
83+ {{
84+ site.data.locales[lang].categories.category_measure.singular
85+ | default: site.data.locales[lang].categories.category_measure
86+ }}
87+ {% endif -%}
88+ ,
89+ {% endif %}
90+
91+ {{ top_posts_size }}
92+
93+ {% if top_posts_size > 1 %}
94+ {{
95+ site.data.locales[lang].categories.post_measure.plural
96+ | default: site.data.locales[lang].categories.post_measure
97+ }}
98+ {% else %}
99+ {{
100+ site.data.locales[lang].categories.post_measure.singular
101+ | default: site.data.locales[lang].categories.post_measure
102+ }}
103+ {% endif %}
104+ </ span >
105+ </ span >
106+
107+ {% if sub_categories_size > 0 %}
108+ < a
109+ href ="#{{ LIST_PREFIX }}{{ group_index }} "
110+ data-bs-toggle ="collapse "
111+ aria-expanded ="true "
112+ aria-label ="{{ HEAD_PREFIX }}{{ group_index }}-trigger "
113+ class ="category-trigger hide-border-bottom "
114+ >
115+ < i class ="fas fa-fw fa-angle-down "> </ i >
116+ </ a >
117+ {% else %}
118+ < span data-bs-toggle ="collapse " class ="category-trigger hide-border-bottom disabled ">
119+ < i class ="fas fa-fw fa-angle-right "> </ i >
120+ </ span >
121+ {% endif %}
122+ </ div >
123+ {% if sub_categories_size > 0 %}
124+ < div id ="{{ LIST_PREFIX }}{{ group_index }} " class ="collapse show " aria-expanded ="true ">
125+ < ul class ="list-group ">
126+ {% for sub_category in sub_categories %}
127+ < li class ="list-group-item ">
128+ < i class ="far fa-folder fa-fw "> </ i >
129+
130+ {% capture _sub_ctg_url %}/categories/{{ sub_category | slugify | url_encode }}/{% endcapture %}
131+ < a href ="{{ _sub_ctg_url | relative_url }} " class ="mx-2 "> {{ sub_category }}</ a >
132+
133+ {% assign posts_size = site.categories[sub_category] | size %}
134+ < span class ="text-muted small font-weight-light ">
135+ {{ posts_size }}
136+
137+ {% if posts_size > 1 %}
138+ {{
139+ site.data.locales[lang].categories.post_measure.plural
140+ | default: site.data.locales[lang].categories.post_measure
141+ }}
142+ {% else %}
143+ {{
144+ site.data.locales[lang].categories.post_measure.singular
145+ | default: site.data.locales[lang].categories.post_measure
146+ }}
147+ {% endif %}
148+ </ span >
149+ </ li >
150+ {% endfor %}
151+ </ ul >
152+ </ div >
153+ {% endif %}
154+ </ div >
155+ {% assign group_index = group_index | plus: 1 %}
156+ {% endif %}
157+ {% endfor %}
0 commit comments