@@ -65,6 +65,8 @@ def get_version_path():
6565    "sphinx_gallery.gen_gallery" ,
6666]
6767
68+ html_favicon  =  "_static/logo-icon.svg" 
69+ 
6870html_baseurl  =  (
6971    f"https://meta-pytorch.org/forge/{ version_path }  "   # needed for sphinx-sitemap 
7072)
@@ -82,8 +84,14 @@ def get_version_path():
8284    "_templates" ,
8385    os .path .join (os .path .dirname (pytorch_sphinx_theme2 .__file__ ), "templates" ),
8486]
85- exclude_patterns  =  ["tutorials/index.rst" , "tutorials/template_tutorial.rst" ]
8687
88+ exclude_patterns  =  [
89+     "tutorials/index.rst" ,
90+     "tutorials/template_tutorial.rst" ,
91+     "tutorials/**/index.rst" ,
92+     "tutorial_sources/**/*.md" ,  # Exclude all markdown files from tutorial_sources 
93+     "tutorial_sources/**/*.MD" ,  # Also exclude uppercase .MD files 
94+ ]
8795html_static_path  =  ["_static" ]
8896html_css_files  =  ["custom.css" ]
8997html_js_files  =  ["custom.js" ]
@@ -167,6 +175,9 @@ def get_version_path():
167175    "html_image" ,
168176]
169177
178+ # Configure MyST parser to treat mermaid code blocks as mermaid directives 
179+ myst_fence_as_directive  =  ["mermaid" ]
180+ 
170181autodoc_default_options  =  {
171182    "members" : True ,
172183    "undoc-members" : True ,
@@ -204,14 +215,15 @@ def get_version_path():
204215sphinx_gallery_conf  =  {
205216    "examples_dirs" : "tutorial_sources" ,  # Path to examples directory 
206217    "gallery_dirs" : "tutorials" ,  # Path to generate gallery 
207-     "filename_pattern" : ".*" ,  # Include all  files 
218+     "filename_pattern" : r ".*\.py$ " ,  # Only process .py files, not .md  files 
208219    "download_all_examples" : False ,
209220    "first_notebook_cell" : "%matplotlib inline" ,
210221    "plot_gallery" : "True" ,
211222    "promote_jupyter_magic" : True ,
212223    "backreferences_dir" : None ,
213224    "show_signature" : False ,
214225    "write_computation_times" : False ,
226+     "ignore_pattern" : r".*\.md$|.*\.MD$" ,  # Explicitly ignore markdown files 
215227}
216228
217229
@@ -222,5 +234,42 @@ def clean_docstring_indentation(app, what, name, obj, options, lines):
222234            lines .append ("" )
223235
224236
237+ def  copy_markdown_tutorials (app ):
238+     """Copy markdown files from tutorial_sources to tutorials directory. 
239+ 
240+     This runs after the builder is initialized but before sphinx-gallery processes files, 
241+     ensuring markdown files are available alongside generated .py tutorials. 
242+     """ 
243+     import  shutil 
244+     from  pathlib  import  Path 
245+ 
246+     source_dir  =  Path (app .srcdir ) /  "tutorial_sources" 
247+     target_dir  =  Path (app .srcdir ) /  "tutorials" 
248+ 
249+     # Ensure target directory exists 
250+     target_dir .mkdir (parents = True , exist_ok = True )
251+ 
252+     # Walk through tutorial_sources and copy all .md files 
253+     for  md_file  in  source_dir .rglob ("*.md" ):
254+         # Skip README files 
255+         if  md_file .name .lower () in  ["readme.md" , "readme.txt" ]:
256+             continue 
257+ 
258+         # Calculate relative path from tutorial_sources 
259+         rel_path  =  md_file .relative_to (source_dir )
260+ 
261+         # Create target path in tutorials directory 
262+         target_path  =  target_dir  /  rel_path 
263+         target_path .parent .mkdir (parents = True , exist_ok = True )
264+ 
265+         # Copy the file 
266+         shutil .copy2 (md_file , target_path )
267+         print (
268+             f"[Forge Docs] Copied { md_file .name }   to { target_path .relative_to (app .srcdir )}  " 
269+         )
270+ 
271+ 
225272def  setup (app ):
226273    app .connect ("autodoc-process-docstring" , clean_docstring_indentation )
274+     # Use builder-inited to ensure it runs before source files are read 
275+     app .connect ("builder-inited" , copy_markdown_tutorials )
0 commit comments