35
35
from living_documentation_generator .model .project_issue import ProjectIssue
36
36
from living_documentation_generator .utils .decorators import safe_call_decorator
37
37
from living_documentation_generator .utils .github_rate_limiter import GithubRateLimiter
38
- from living_documentation_generator .utils .utils import make_issue_key , generate_root_level_index_page
38
+ from living_documentation_generator .utils .utils import make_issue_key , generate_root_level_index_page , load_template
39
39
from living_documentation_generator .utils .constants import (
40
40
ISSUES_PER_PAGE_LIMIT ,
41
41
ISSUE_STATE_ALL ,
@@ -294,57 +294,16 @@ def _generate_markdown_pages(self, issues: dict[str, ConsolidatedIssue]) -> None
294
294
is_structured_output = ActionInputs .get_is_structured_output_enabled ()
295
295
is_grouping_by_topics = ActionInputs .get_is_grouping_by_topics_enabled ()
296
296
output_path = ActionInputs .get_output_directory ()
297
- issue_page_detail_template = None
298
- index_page_template = None
299
- index_root_level_page = None
300
- index_org_level_template = None
301
- index_repo_page_template = None
302
- index_data_level_template = None
303
297
304
298
# Load the template files for generating the Markdown pages
305
- try :
306
- with open (LivingDocumentationGenerator .ISSUE_PAGE_TEMPLATE_FILE , "r" , encoding = "utf-8" ) as f :
307
- issue_page_detail_template = f .read ()
308
- except IOError :
309
- logger .error ("Issue page template file was not successfully loaded." , exc_info = True )
310
-
311
- try :
312
- with open (LivingDocumentationGenerator .INDEX_NO_STRUCT_TEMPLATE_FILE , "r" , encoding = "utf-8" ) as f :
313
- index_page_template = f .read ()
314
- except IOError :
315
- logger .error ("Index page template file was not successfully loaded." , exc_info = True )
316
-
317
- try :
318
- with open (LivingDocumentationGenerator .INDEX_ROOT_LEVEL_TEMPLATE_FILE , "r" , encoding = "utf-8" ) as f :
319
- index_root_level_page = f .read ()
320
- except IOError :
321
- logger .error (
322
- "Structured index page template file for root level was not successfully loaded." , exc_info = True
323
- )
324
-
325
- try :
326
- with open (LivingDocumentationGenerator .INDEX_ORG_LEVEL_TEMPLATE_FILE , "r" , encoding = "utf-8" ) as f :
327
- index_org_level_template = f .read ()
328
- except IOError :
329
- logger .error (
330
- "Structured index page template file for organization level was not successfully loaded." , exc_info = True
331
- )
332
-
333
- try :
334
- with open (LivingDocumentationGenerator .INDEX_TOPIC_PAGE_TEMPLATE_FILE , "r" , encoding = "utf-8" ) as f :
335
- index_repo_page_template = f .read ()
336
- except IOError :
337
- logger .error (
338
- "Structured index page template file for repository level was not successfully loaded." , exc_info = True
339
- )
340
-
341
- try :
342
- with open (LivingDocumentationGenerator .INDEX_DATA_LEVEL_TEMPLATE_FILE , "r" , encoding = "utf-8" ) as f :
343
- index_data_level_template = f .read ()
344
- except IOError :
345
- logger .error (
346
- "Structured index page template file for data level was not successfully loaded." , exc_info = True
347
- )
299
+ (
300
+ issue_page_detail_template ,
301
+ index_page_template ,
302
+ index_root_level_page ,
303
+ index_org_level_template ,
304
+ index_repo_page_template ,
305
+ index_data_level_template ,
306
+ ) = self ._load_all_templates ()
348
307
349
308
# Generate a markdown page for every issue
350
309
for consolidated_issue in issues .values ():
@@ -361,7 +320,7 @@ def _generate_markdown_pages(self, issues: dict[str, ConsolidatedIssue]) -> None
361
320
# Generate an index page with a summary table about all issues grouped by topics
362
321
elif is_grouping_by_topics :
363
322
issues = list (issues .values ())
364
- topics = set ([ issue .topic for issue in issues ])
323
+ topics = { issue .topic for issue in issues }
365
324
generate_root_level_index_page (index_root_level_page , output_path )
366
325
367
326
for topic in topics :
@@ -447,14 +406,15 @@ def _generate_structured_index_pages(
447
406
organization_name ,
448
407
)
449
408
409
+ # Generate an index pages for the documentation based on the grouped issues by topics
450
410
if ActionInputs .get_is_grouping_by_topics_enabled ():
451
411
self ._generate_sub_level_index_page (index_repo_level_template , "repo" , repository_id )
452
412
logger .debug (
453
413
"Generated repository level _index.md` for repository: %s." ,
454
414
repository_name ,
455
415
)
456
416
457
- topics = set ([ issue .topic for issue in issues ])
417
+ topics = { issue .topic for issue in issues }
458
418
for topic in topics :
459
419
self ._generate_index_page (index_data_level_template , issues , repository_id , topic )
460
420
logger .debug (
@@ -465,7 +425,7 @@ def _generate_structured_index_pages(
465
425
else :
466
426
self ._generate_index_page (index_data_level_template , issues , repository_id )
467
427
logger .debug (
468
- "Generated repository level `_index.md` for %s" ,
428
+ "Generated data level `_index.md` for %s" ,
469
429
repository_id ,
470
430
)
471
431
@@ -700,3 +660,44 @@ def _generate_index_directory_path(repository_id: Optional[str], topic: Optional
700
660
os .makedirs (output_path , exist_ok = True )
701
661
702
662
return output_path
663
+
664
+ @staticmethod
665
+ def _load_all_templates () -> tuple [str , ...]:
666
+ """
667
+ Load all template files for generating the Markdown pages.
668
+
669
+ @return: A tuple containing all loaded template files.
670
+ """
671
+ issue_page_detail_template = load_template (
672
+ LivingDocumentationGenerator .ISSUE_PAGE_TEMPLATE_FILE ,
673
+ "Issue page template file was not successfully loaded." ,
674
+ )
675
+ index_page_template = load_template (
676
+ LivingDocumentationGenerator .INDEX_NO_STRUCT_TEMPLATE_FILE ,
677
+ "Index page template file was not successfully loaded." ,
678
+ )
679
+ index_root_level_page = load_template (
680
+ LivingDocumentationGenerator .INDEX_ROOT_LEVEL_TEMPLATE_FILE ,
681
+ "Structured index page template file for root level was not successfully loaded." ,
682
+ )
683
+ index_org_level_template = load_template (
684
+ LivingDocumentationGenerator .INDEX_ORG_LEVEL_TEMPLATE_FILE ,
685
+ "Structured index page template file for organization level was not successfully loaded." ,
686
+ )
687
+ index_repo_page_template = load_template (
688
+ LivingDocumentationGenerator .INDEX_TOPIC_PAGE_TEMPLATE_FILE ,
689
+ "Structured index page template file for repository level was not successfully loaded." ,
690
+ )
691
+ index_data_level_template = load_template (
692
+ LivingDocumentationGenerator .INDEX_DATA_LEVEL_TEMPLATE_FILE ,
693
+ "Structured index page template file for data level was not successfully loaded." ,
694
+ )
695
+
696
+ return (
697
+ issue_page_detail_template ,
698
+ index_page_template ,
699
+ index_root_level_page ,
700
+ index_org_level_template ,
701
+ index_repo_page_template ,
702
+ index_data_level_template ,
703
+ )
0 commit comments