@@ -145,40 +145,59 @@ def output_toc(data)
145
145
categories = data [ 'categories' ]
146
146
147
147
parents , children = categories . partition { |category | category [ 'parent' ] . nil? }
148
+
149
+ # Use a nested list for the contents section
148
150
parents . each do |parent |
149
151
parent_id = parent [ 'id' ]
150
152
# Only include parent categories with projects or with children that have projects
151
153
if has_projects_recursive ( projects , categories , parent_id )
152
- output << "- [#{ parent [ 'title' ] } ](##{ parent_id } )\n "
153
-
154
- children . sort_by { |category | category [ 'id' ] }
155
- . select { |category | category [ 'parent' ] == parent_id } . each do |child |
156
- child_id = child [ 'id' ]
154
+ parent_children = children . select { |category | category [ 'parent' ] == parent_id }
155
+ . sort_by { |category | category [ 'id' ] }
156
+ . select { |category | has_projects_recursive ( projects , categories , category [ 'id' ] ) }
157
+
158
+ # If parent has child categories with projects, make it a list item with nested items
159
+ if parent_children . any?
160
+ output << "- **[#{ parent [ 'title' ] } ](##{ parent_id } )**\n "
157
161
158
- # Only include child categories with projects or with grandchildren that have projects
159
- if has_projects_recursive ( projects , categories , child_id )
160
- output << " - [#{ child [ 'title' ] } ](##{ child_id } )\n "
161
-
162
- children . sort_by { |category | category [ 'id' ] }
163
- . select { |category | category [ 'parent' ] == child_id } . each do |grandchild |
164
- grandchild_id = grandchild [ 'id' ]
162
+ # Add child categories as nested list items
163
+ parent_children . each do |child |
164
+ child_id = child [ 'id' ]
165
+ child_grandchildren = children . select { |category | category [ 'parent' ] == child_id }
166
+ . sort_by { |category | category [ 'id' ] }
167
+ . select { |category | has_projects_recursive ( projects , categories , category [ 'id' ] ) }
168
+
169
+ # If child has grandchildren with projects, make it a list item with nested items
170
+ if child_grandchildren . any?
171
+ output << " - **[#{ child [ 'title' ] } ](##{ child_id } )**\n "
165
172
166
- # Only include grandchild categories with projects or with great-grandchildren that have projects
167
- if has_projects_recursive ( projects , categories , grandchild_id )
168
- output << " - [#{ grandchild [ 'title' ] } ](##{ grandchild_id } )\n "
169
-
170
- children . sort_by { |category | category [ 'id' ] }
171
- . select { |category | category [ 'parent' ] == grandchild_id } . each do |great_grandchild |
172
- great_grandchild_id = great_grandchild [ 'id' ]
173
+ # Add grandchild categories as nested list items
174
+ child_grandchildren . each do |grandchild |
175
+ grandchild_id = grandchild [ 'id' ]
176
+ grandchild_great_grandchildren = children . select { |category | category [ 'parent' ] == grandchild_id }
177
+ . sort_by { |category | category [ 'id' ] }
178
+ . select { |category | has_projects ( projects , category [ 'id' ] ) }
179
+
180
+ # If grandchild has great-grandchildren with projects, make it a list item with nested items
181
+ if grandchild_great_grandchildren . any?
182
+ output << " - **[#{ grandchild [ 'title' ] } ](##{ grandchild_id } )**\n "
173
183
174
- # Only include great-grandchild categories with projects
175
- if has_projects ( projects , great_grandchild_id )
176
- output << " - [#{ great_grandchild [ 'title' ] } ](##{ great_grandchild_id } )\n "
184
+ # Add great-grandchild categories as nested list items
185
+ grandchild_great_grandchildren . each do | great_grandchild |
186
+ output << " - [#{ great_grandchild [ 'title' ] } ](##{ great_grandchild [ 'id' ] } )\n "
177
187
end
188
+ else
189
+ # Grandchild has no children, so it's a simple list item
190
+ output << " - [#{ grandchild [ 'title' ] } ](##{ grandchild_id } )\n "
178
191
end
179
192
end
193
+ else
194
+ # Child has no grandchildren, so it's a simple list item
195
+ output << " - [#{ child [ 'title' ] } ](##{ child_id } )\n "
180
196
end
181
197
end
198
+ else
199
+ # Parent has no children, so it's a simple list item
200
+ output << "- [#{ parent [ 'title' ] } ](##{ parent_id } )\n "
182
201
end
183
202
end
184
203
end
0 commit comments