@@ -23,12 +23,60 @@ <h1>{{ page.title }}</h1>
2323
2424<!-- All documents in category -->
2525 < section class ="category-documents ">
26- {% assign category_docs = site.documents | where: "category", page.category | where_exp: "doc", "doc.status != 'archived'" | sort: "reading_order" %}
27-
26+
27+ {% comment %} Get all posts and collection documents that match this category {% endcomment %}
28+ {% assign category_docs = "" | split: "" %}
29+
30+ {% comment %} First, get posts with matching category {% endcomment %}
31+ {% for post in site.posts %}
32+ {% comment %} Check if post category matches page category or page title {% endcomment %}
33+ {% if post.category == page.category or post.categories contains page.category or post.category == page.title or post.categories contains page.title %}
34+ {% unless post.status == 'archived' %}
35+ {% assign category_docs = category_docs | push: post %}
36+ {% endunless %}
37+ {% endif %}
38+ {% endfor %}
39+
40+ {% comment %} Then, check if there's a collection with the same name {% endcomment %}
41+ {% assign collection_key = page.collection_name | default: page.category %}
42+ {% if collection_key and collection_key != "" %}
43+ {% assign collection_key = collection_key | downcase | replace: ' ', '_' | replace: '&', 'and' %}
44+ {% assign collection_docs = site[collection_key] %}
45+ {% if collection_docs %}
46+ {% for doc in collection_docs %}
47+ {% unless doc.status == 'archived' %}
48+ {% assign category_docs = category_docs | push: doc %}
49+ {% endunless %}
50+ {% endfor %}
51+ {% endif %}
52+ {% endif %}
53+
54+ {% comment %} Sort all documents by reading_order if present, otherwise by date {% endcomment %}
2855 {% if category_docs.size > 0 %}
29-
56+ {% assign docs_with_order = "" | split: "" %}
57+ {% assign docs_without_order = "" | split: "" %}
58+ {% for doc in category_docs %}
59+ {% if doc.reading_order %}
60+ {% assign docs_with_order = docs_with_order | push: doc %}
61+ {% else %}
62+ {% assign docs_without_order = docs_without_order | push: doc %}
63+ {% endif %}
64+ {% endfor %}
65+ {% assign docs_with_order = docs_with_order | sort: "reading_order" %}
66+ {% assign docs_without_order = docs_without_order | sort: "date" | reverse %}
67+ {% assign category_docs = docs_with_order | concat: docs_without_order %}
68+ {% endif %}
69+
70+ {% if category_docs and category_docs.size > 0 %}
71+
3072 <!-- Reading Path -->
31- {% assign ordered_docs = category_docs | where_exp: "doc", "doc.reading_order" | sort: "reading_order" %}
73+ {% assign ordered_docs = "" | split: "" %}
74+ {% for doc in category_docs %}
75+ {% if doc.reading_order %}
76+ {% assign ordered_docs = ordered_docs | push: doc %}
77+ {% endif %}
78+ {% endfor %}
79+ {% assign ordered_docs = ordered_docs | sort: 'reading_order' %}
3280 {% if ordered_docs.size > 1 %}
3381 < div class ="reading-path ">
3482 < h2 > Suggested Reading Path</ h2 >
@@ -44,7 +92,7 @@ <h2>Suggested Reading Path</h2>
4492 </ ol >
4593 </ div >
4694 {% endif %}
47-
95+
4896 <!-- All Documents -->
4997 < div class ="all-documents ">
5098 < h2 > All Documents</ h2 >
@@ -58,11 +106,92 @@ <h3><a href="{{ doc.url | relative_url }}">{{ doc.title }}</a></h3>
58106 {% endfor %}
59107 </ div >
60108 </ div >
61-
109+
62110 {% else %}
63- < p > No documents found in this category.</ p >
111+ < div class ="category-diagnostics ">
112+ < p > No documents found in this category.</ p >
113+
114+ < details >
115+ < summary > Diagnostic Information</ summary >
116+ < div class ="diagnostic-info ">
117+ < h4 > Page Variables:</ h4 >
118+ < ul >
119+ < li > < strong > page.category:</ strong > {{ page.category | inspect }}</ li >
120+ < li > < strong > page.collection_name:</ strong > {{ page.collection_name | inspect }}</ li >
121+ < li > < strong > page.title:</ strong > {{ page.title | inspect }}</ li >
122+ < li > < strong > collection_key:</ strong > {{ collection_key | inspect }}</ li >
123+ </ ul >
124+
125+ < h4 > Available Collections:</ h4 >
126+ < ul >
127+ {% for collection in site.collections %}
128+ < li > < strong > {{ collection.label }}:</ strong > {{ site[collection.label] | size }} documents</ li >
129+ {% endfor %}
130+ </ ul >
131+
132+ < h4 > Posts Analysis:</ h4 >
133+ < ul >
134+ < li > < strong > Total posts:</ strong > {{ site.posts.size }}</ li >
135+ < li > < strong > Posts with categories:</ strong >
136+ {% assign posts_with_cats = 0 %}
137+ {% for post in site.posts %}
138+ {% if post.categories.size > 0 or post.category %}
139+ {% assign posts_with_cats = posts_with_cats | plus: 1 %}
140+ {% endif %}
141+ {% endfor %}
142+ {{ posts_with_cats.size }}
143+ </ li >
144+ </ ul >
145+
146+ < h4 > Posts by Category:</ h4 >
147+ < ul >
148+ {% assign all_categories = "" | split: "" %}
149+ {% for post in site.posts %}
150+ {% if post.category %}
151+ {% unless all_categories contains post.category %}
152+ {% assign all_categories = all_categories | push: post.category %}
153+ {% endunless %}
154+ {% endif %}
155+ {% for cat in post.categories %}
156+ {% unless all_categories contains cat %}
157+ {% assign all_categories = all_categories | push: cat %}
158+ {% endunless %}
159+ {% endfor %}
160+ {% endfor %}
161+ {% for category in all_categories %}
162+ {% assign cat_posts = site.posts | where: 'category', category %}
163+ < li > < strong > {{ category }}:</ strong > {{ cat_posts.size }} posts</ li >
164+ {% endfor %}
165+ </ ul >
166+
167+ < h4 > Collection Check:</ h4 >
168+ {% assign collection_docs = site[collection_key] %}
169+ {% if collection_docs %}
170+ < p > < strong > Collection "{{ collection_key }}" found:</ strong > {{ collection_docs | size }} documents</ p >
171+ < ul >
172+ {% for doc in collection_docs limit: 5 %}
173+ < li > {{ doc.title }} (status: {{ doc.status | default: "none" }})</ li >
174+ {% endfor %}
175+ {% if collection_docs.size > 5 %}
176+ < li > ... and {{ collection_docs.size | minus: 5 }} more</ li >
177+ {% endif %}
178+ </ ul >
179+ {% else %}
180+ < p > < strong > Collection "{{ collection_key | default: "(empty)" }}" not found</ strong > </ p >
181+ {% endif %}
182+
183+ < h4 > Matching Logic Test:</ h4 >
184+ < p > Looking for posts where:</ p >
185+ < ul >
186+ < li > post.category == "{{ page.category }}" OR</ li >
187+ < li > post.categories contains "{{ page.category }}"</ li >
188+ < li > AND post.status != "archived"</ li >
189+ </ ul >
190+ </ div >
191+ </ details >
192+ </ div >
64193 {% endif %}
65-
194+
66195 </ section >
67196
68197</ div >
0 commit comments