17
17
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18
18
#
19
19
20
- # Sphinx hardcodes that certain output directories have names starting with
20
+ # Sphinx hardcodes that certain output paths have names starting with
21
21
# an underscore.
22
22
# Jekyll hardcodes that filenames starting with an underscore are not
23
23
# deployed to the website.
24
- # Rename Sphinx output directories to drop the underscore.
24
+ # Rename Sphinx output paths to drop the underscore.
25
25
26
26
import os
27
27
32
32
'_static' : 'static' ,
33
33
'_sources' : 'sources' ,
34
34
}
35
+ FILES = {
36
+ # Added in Sphinx 5.0.0, scheduled to be removed in Sphinx 6
37
+ 'static/_sphinx_javascript_frameworks_compat.js' : 'static/sphinx_javascript_frameworks_compat.js' , # noqa: E501
38
+ }
35
39
REWRITE_EXTENSIONS = {'.html' , '.js' }
36
40
37
41
38
- def remove_directory_underscores (app , exception ):
42
+ def remove_path_underscores (app , exception ):
39
43
if exception :
40
44
return
41
45
# Get logger
42
46
logger = logging .getLogger (__name__ )
43
- logger .info (bold ('fixing directory names ... ' ), nonl = True )
47
+ logger .info (bold ('fixing pathnames ... ' ), nonl = True )
44
48
# Rewrite references in HTML/JS files
45
49
for dirpath , _ , filenames in os .walk (app .outdir ):
46
50
for filename in filenames :
@@ -51,6 +55,8 @@ def remove_directory_underscores(app, exception):
51
55
contents = fh .read ()
52
56
for old , new in DIRS .items ():
53
57
contents = contents .replace (old + '/' , new + '/' )
58
+ for old , new in FILES .items ():
59
+ contents = contents .replace (old , new )
54
60
with open (path , 'w' , encoding = 'utf-8' ) as fh :
55
61
fh .write (contents )
56
62
# Move directory contents
@@ -65,8 +71,14 @@ def remove_directory_underscores(app, exception):
65
71
newfile = os .path .join (newdir , filename )
66
72
os .rename (oldfile , newfile )
67
73
os .rmdir (olddir )
74
+ # Move files
75
+ for old , new in FILES .items ():
76
+ oldfile = os .path .join (app .outdir , old )
77
+ newfile = os .path .join (app .outdir , new )
78
+ if os .path .isfile (oldfile ):
79
+ os .rename (oldfile , newfile )
68
80
logger .info ('done' )
69
81
70
82
71
83
def setup (app ):
72
- app .connect ('build-finished' , remove_directory_underscores )
84
+ app .connect ('build-finished' , remove_path_underscores )
0 commit comments