@@ -13,27 +13,34 @@ def insert_runllm_widget(html_content):
1313 return re .sub (r"</body>" , f"{ widget_script } \n </body>" , html_content )
1414
1515
16+ def process_html_files (build_dir ):
17+ for root , dirs , files in os .walk (build_dir ):
18+ for file in files :
19+ if file .endswith (".html" ):
20+ file_path = os .path .join (root , file )
21+
22+ # Read the HTML file
23+ with open (file_path , "r" , encoding = "utf-8" ) as f :
24+ content = f .read ()
25+
26+ # Insert the RunLLM widget
27+ modified_content = insert_runllm_widget (content )
28+
29+ # Write back the modified content
30+ with open (file_path , "w" , encoding = "utf-8" ) as f :
31+ f .write (modified_content )
32+
33+
1634def main ():
1735 # Get the build directory path
1836 build_dir = os .path .join (
1937 os .path .dirname (os .path .abspath (__file__ )), "_build" , "html"
2038 )
21- index_file = os .path .join (build_dir , "index.html" )
22-
23- # Process only index.html
24- if os .path .exists (index_file ):
25- # Read the HTML file
26- with open (index_file , "r" , encoding = "utf-8" ) as f :
27- content = f .read ()
28-
29- # Insert the RunLLM widget
30- modified_content = insert_runllm_widget (content )
31-
32- # Write back the modified content
33- with open (index_file , "w" , encoding = "utf-8" ) as f :
34- f .write (modified_content )
39+ # Process all HTML files
40+ if os .path .exists (build_dir ):
41+ process_html_files (build_dir )
3542 else :
36- print (f"Index file not found: { index_file } " )
43+ print (f"Build directory not found: { build_dir } " )
3744
3845
3946if __name__ == "__main__" :
0 commit comments