@@ -280,21 +280,39 @@ def fix_gallery_edit_links(app, pagename, templatename, context, doctree):
280
280
):
281
281
parts = pagename .split ("/" )
282
282
gallery_dir = parts [0 ]
283
+ # Handle nested directories by joining all parts except the first
284
+ example_path = "/" .join (parts [1 :])
283
285
example_name = parts [- 1 ]
284
286
285
- source_dirs = {
286
- "beginner" : "beginner_source" ,
287
- "intermediate" : "intermediate_source" ,
288
- "advanced" : "advanced_source" ,
289
- "recipes" : "recipes_source" ,
290
- "prototype" : "prototype_source" ,
291
- }
287
+ source_dirs = {}
288
+ for i in range ( len ( sphinx_gallery_conf [ "examples_dirs" ])):
289
+ gallery_dir = sphinx_gallery_conf [ "gallery_dirs" ][ i ]
290
+ source_dir = sphinx_gallery_conf [ "examples_dirs" ][ i ]
291
+ # Extract the base name without "_source" suffix
292
+ gallery_base = gallery_dir
293
+ source_dirs [ gallery_base ] = source_dir
292
294
293
295
if gallery_dir in source_dirs :
294
296
source_dir = source_dirs [gallery_dir ]
297
+
298
+ # Reconstruct the path preserving subdirectories
299
+ subdir = "/" .join (parts [1 :- 1 ]) if len (parts ) > 2 else ""
300
+
295
301
# Check if .py file exists
296
- py_path = f"{ source_dir } /{ example_name } .py"
297
- rst_path = f"{ source_dir } /{ example_name } .rst"
302
+ py_path = (
303
+ f"{ source_dir } /{ subdir } /{ example_name } .py"
304
+ if subdir
305
+ else f"{ source_dir } /{ example_name } .py"
306
+ )
307
+ rst_path = (
308
+ f"{ source_dir } /{ subdir } /{ example_name } .rst"
309
+ if subdir
310
+ else f"{ source_dir } /{ example_name } .rst"
311
+ )
312
+
313
+ # Clean up any double slashes
314
+ py_path = py_path .replace ("//" , "/" )
315
+ rst_path = rst_path .replace ("//" , "/" )
298
316
299
317
# Default to .py file, fallback to .rst if needed
300
318
file_path = py_path
@@ -345,7 +363,7 @@ def fix_gallery_edit_links(app, pagename, templatename, context, doctree):
345
363
"Thumbs.db" ,
346
364
".DS_Store" ,
347
365
"src/pytorch-sphinx-theme/docs*" ,
348
- # "**/huggingface_hub /templates/**",
366
+ # "**/huggindef fix_gallery_edit_linksgface_hub /templates/**",
349
367
]
350
368
exclude_patterns += sphinx_gallery_conf ["examples_dirs" ]
351
369
exclude_patterns += ["*/index.rst" ]
0 commit comments