@@ -121,6 +121,14 @@ def create_simple_redirects(graph_edges: dict) -> dict:
121121 return redirects
122122
123123
124+ def remove_suffix (docname : str , suffixes : List [str ]) -> str :
125+ """Remove any known suffixes for a file path."""
126+ for suffix in suffixes :
127+ if docname .endswith (suffix ):
128+ return docname [: - len (suffix )]
129+ return docname
130+
131+
124132def build_redirects (app : Sphinx , exception : Union [Exception , None ]) -> None :
125133 """
126134 Build amd write redirects
@@ -206,18 +214,22 @@ def build_redirects(app: Sphinx, exception: Union[Exception, None]) -> None:
206214 src_redirect_from = Path (PureWindowsPath (src_redirect_from ))
207215 src_redirect_to = Path (PureWindowsPath (src_redirect_to ))
208216
209- # relative paths from source dir (without ext)
210- redirect_from = src_redirect_from .with_suffix ("" )
211- redirect_to = src_redirect_to .with_suffix ("" )
217+ # remove extensions
218+ redirect_from_name = remove_suffix (
219+ src_redirect_from .name , app .config .source_suffix
220+ )
221+ redirect_to_name = remove_suffix (src_redirect_to .name , app .config .source_suffix )
222+
223+ redirect_from = src_redirect_from .parent / f"{ redirect_from_name } .html"
224+ redirect_to = src_redirect_to .parent / f"{ redirect_to_name } .html"
212225
213226 if type (app .builder ) == DirectoryHTMLBuilder :
214- if redirect_from .name != "index" :
215- redirect_from = redirect_from / "index"
216- if redirect_to .name != "index" :
217- redirect_to = redirect_to / "index"
218-
219- redirect_from = redirect_from .with_suffix (".html" )
220- redirect_to = redirect_to .with_suffix (".html" )
227+ if redirect_from_name != "index" :
228+ redirect_from = (
229+ src_redirect_from .parent / redirect_from_name / "index.html"
230+ )
231+ if redirect_to_name != "index" :
232+ redirect_to = src_redirect_to .parent / redirect_to_name / "index.html"
221233
222234 # absolute paths into the build dir
223235 build_redirect_from = Path (app .outdir ) / redirect_from
0 commit comments