11import argparse
22from pathlib import Path
3- import shutil
3+ import json
4+ import os
45
56from jinja2 import Template
67
@@ -146,6 +147,34 @@ def generate_operator_doc(server, operator_name, include_private):
146147 with Path .open (Path (file_dir ) / f"{ file_name } .md" , "w" ) as file :
147148 file .write (output )
148149
150+ def generate_toc_tree (docs_path ):
151+ data = []
152+ for folder in docs_path .iterdir ():
153+ if folder .is_dir (): # Ensure 'folder' is a directory
154+ category = folder .name
155+ operators = [] # Reset operators for each category
156+ for file in folder .iterdir ():
157+ if file .is_file () and file .suffix == ".md" : # Ensure 'file' is a file with .md extension
158+ file_name = file .name
159+ operator_name = file_name .replace ("_" , " " ).replace (".md" , "" )
160+ operators .append ({"operator_name" : operator_name , "file_name" : file_name })
161+ data .append ({"category" : category , "operators" : operators })
162+
163+ # Write the JSON file for debugging purposes
164+ with open (docs_path / "toc_tree.json" , "w" ) as file :
165+ json .dump (data , file , indent = 4 )
166+
167+ # Render the Jinja2 template
168+ template_path = docs_path / "toc_template.j2"
169+ with open (template_path , "r" ) as template_file :
170+ template = Template (template_file .read ())
171+ output = template .render (data = data ) # Pass 'data' as a named argument
172+
173+ # Write the rendered output to toc.md
174+ with open (docs_path / "toc.md" , "w" ) as file :
175+ file .write (output )
176+
177+
149178
150179def main ():
151180 parser = argparse .ArgumentParser (description = "Fetch available operators" )
@@ -169,6 +198,10 @@ def main():
169198 for operator_name in operators :
170199 generate_operator_doc (server , operator_name , args .include_private )
171200
201+ docs_path = Path (__file__ ).parent .parent / "doc" / "source" / "operators_doc"
202+ print (docs_path )
203+ generate_toc_tree (docs_path )
204+
172205
173206if __name__ == "__main__" :
174207 main ()
0 commit comments