Skip to content

Commit b8361d7

Browse files
committed
Update
1 parent 6715867 commit b8361d7

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

conf.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,8 @@ def wrapper(*args, **kwargs):
158158
"author": "PyTorch Contributors",
159159
}
160160

161+
162+
161163
# -- Sphinx-gallery configuration --------------------------------------------
162164

163165
sphinx_gallery_conf = {
@@ -187,6 +189,11 @@ def wrapper(*args, **kwargs):
187189
},
188190
}
189191

192+
html_additional_pages = {
193+
"404": "404.html",
194+
}
195+
196+
190197
html_baseurl = "https://pytorch.org/tutorials/" # needed for sphinx-sitemap
191198
sitemap_locales = [None]
192199
sitemap_excludes = [
@@ -259,6 +266,22 @@ def wrapper(*args, **kwargs):
259266
r"/(?!" + re.escape(os.getenv("GALLERY_PATTERN")) + r")[^/]+$"
260267
)
261268

269+
# Add 404.html to each gallery directory and all subdirectories
270+
for i, gallery_dir in enumerate(sphinx_gallery_conf["gallery_dirs"]):
271+
# Add 404.html to the main gallery directory
272+
html_additional_pages[f"{gallery_dir}/404"] = "404.html"
273+
274+
# Add 404.html to all subdirectories in the corresponding source directory
275+
source_dir = Path(sphinx_gallery_conf["examples_dirs"][i])
276+
if source_dir.exists():
277+
# Find all subdirectories in the source directory
278+
for subdir in source_dir.rglob("*"):
279+
if subdir.is_dir() and subdir != source_dir:
280+
# Calculate the relative path and corresponding gallery path
281+
relative_path = subdir.relative_to(source_dir)
282+
gallery_subdir = f"{gallery_dir}/{relative_path}"
283+
html_additional_pages[f"{gallery_subdir}/404"] = "404.html"
284+
262285
for i in range(len(sphinx_gallery_conf["examples_dirs"])):
263286
gallery_dir = Path(sphinx_gallery_conf["gallery_dirs"][i])
264287
source_dir = Path(sphinx_gallery_conf["examples_dirs"][i])

0 commit comments

Comments
 (0)