@@ -145,10 +145,38 @@ def generate_report(self, output_dir: str = SECTIONS_DIR) -> None:
145145
146146 # Generate the home page and update the report manager content
147147 # ! top level files (compontents) are added to the home page
148+ home_section = self .report .sections [0 ]
148149 self ._generate_home_section (
149150 output_dir = output_dir ,
150151 report_manag_content = report_manag_content ,
151- home_section = self .report .sections [0 ],
152+ home_section = home_section ,
153+ )
154+ # ! move this into the _generate_home_section method
155+ subsection_page_vars = []
156+
157+ for subsection in home_section .subsections :
158+ # ! could add a non-integer to ensure it's a valid identifier
159+ subsection_name_var = make_valid_identifier (subsection .title )
160+ if not subsection_name_var .isidentifier ():
161+ self .report .logger .warning (
162+ f"Subsection name '{ subsection_name_var } ' is not a valid identifier."
163+ )
164+ raise ValueError (
165+ f"Subsection name is not a valid Python identifier: { subsection_name_var } "
166+ )
167+ subsection_file_path = (
168+ Path ("Home" ) / f"{ subsection_name_var } .py"
169+ ).as_posix () # Make sure it's Posix Paths
170+ subsection .file_path = subsection_file_path
171+ # Create a Page object for each subsection and add it to the home page content
172+ report_manag_content .append (
173+ f"{ subsection_name_var } = st.Page('{ subsection_file_path } ', title='{ subsection .title } ')"
174+ )
175+ subsection_page_vars .append (subsection_name_var )
176+
177+ # Add all subsection Page objects to the corresponding section
178+ report_manag_content .append (
179+ f"sections_pages['Home'] = [homepage,{ ', ' .join (subsection_page_vars )} ]\n "
152180 )
153181
154182 for section in self .report .sections [1 :]: # skip home section components
@@ -427,14 +455,13 @@ def _generate_sections(self, output_dir: str) -> None:
427455 The folder where section files will be saved.
428456 """
429457 self .report .logger .info ("Starting to generate sections for the report." )
430-
431458 try :
432- for section in self .report .sections [ 1 :] :
459+ for section_no , section in enumerate ( self .report .sections ) :
433460 self .report .logger .debug (
434461 f"Processing section '{ section .id } ': '{ section .title } ' - { len (section .subsections )} subsection(s)"
435462 )
436-
437- if section .components :
463+ # ! skip first section components as it's predefined as homepage
464+ if section_no and section .components :
438465 # add an section overview page
439466 section_content , section_imports , _ = self ._combine_components (
440467 section .components
@@ -449,9 +476,8 @@ def _generate_sections(self, output_dir: str) -> None:
449476 )
450477
451478 if not section .subsections :
452- self .report .logger .warning (
453- f"No subsections found in section: '{ section .title } '. "
454- "To show content in the report, add subsections to the section."
479+ self .report .logger .debug (
480+ f"No subsections found in section: '{ section .title } '."
455481 )
456482 continue
457483
0 commit comments