@@ -211,6 +211,35 @@ def _filter_list(self, post_list, lang):
211
211
else :
212
212
return [x for x in post_list if x .is_translation_available (lang )]
213
213
214
+ def _generate_subclassification_page (self , taxonomy , node , context , kw , lang ):
215
+ """Render a list of subclassifications."""
216
+ def get_subnode_data (subnode ):
217
+ return [
218
+ taxonomy .get_classification_printable_name (subnode .classification_path , lang , only_last_component = True ),
219
+ self .site .link (taxonomy .classification_name , subnode .classification_name , lang ),
220
+ len (self ._filter_list (self .site .posts_per_classification [taxonomy .classification_name ][lang ][subnode .classification_name ]))
221
+ ]
222
+
223
+ items = [get_subnode_data (subnode ) for subnode in node .children ]
224
+ context = copy (context )
225
+ context ["lang" ] = lang
226
+ context ["permalink" ] = self .site .link (taxonomy .classification_name , node .classification_name , lang )
227
+ if "pagekind" not in context :
228
+ context ["pagekind" ] = ["list" , "archive_page" ]
229
+ context ["items" ] = items
230
+ task = self .site .generic_post_list_renderer (
231
+ lang ,
232
+ [],
233
+ os .path .join (kw ['output_folder' ], self .site .path (taxonomy .classification_name , node .classification_name , lang )),
234
+ taxonomy .show_list_as_subcategories_list ,
235
+ kw ['filters' ],
236
+ context ,
237
+ )
238
+ task_cfg = {1 : kw , 2 : items }
239
+ task ['uptodate' ] = task ['uptodate' ] + [utils .config_changed (task_cfg , 'nikola.plugins.task.taxonomy' )]
240
+ task ['basename' ] = self .name
241
+ return task
242
+
214
243
def _generate_classification_page (self , taxonomy , classification , post_list , lang ):
215
244
"""Render index or post list and associated feeds per classification."""
216
245
# Filter list
@@ -235,6 +264,14 @@ def _generate_classification_page(self, taxonomy, classification, post_list, lan
235
264
kw ["output_folder" ] = self .site .config ['OUTPUT_FOLDER' ]
236
265
context = copy (context )
237
266
context ["permalink" ] = self .site .link (taxonomy .classification_name , classification , lang )
267
+ # Decide what to do
268
+ if taxonomy .has_hierarchy and taxonomy .show_list_as_subcategories_list :
269
+ # Determine whether there are subcategories
270
+ node = self .site .hierarchy_lookup_per_classification [taxonomy .classification_name ][lang ][classification ]
271
+ # Are there subclassifications?
272
+ if len (node .children ) > 0 :
273
+ # Yes: create list with subclassifications instead of list of posts
274
+ return self ._generate_subclassification_page (taxonomy , node , context , kw , lang )
238
275
# Generate RSS feed
239
276
if kw ["generate_rss" ]:
240
277
yield self ._generate_classification_page_as_rss (taxonomy , classification , filtered_posts , context ['title' ], context .get ("description" ), kw , lang )
0 commit comments