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