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
28
+ from sphinx .util import logging
28
29
from sphinx .util .console import bold
29
30
30
31
DIRS = {
31
32
'_static' : 'static' ,
32
33
'_sources' : 'sources' ,
33
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
+ }
34
39
REWRITE_EXTENSIONS = {'.html' , '.js' }
35
40
36
41
37
- def remove_directory_underscores (app , exception ):
42
+ def remove_path_underscores (app , exception ):
38
43
if exception :
39
44
return
40
45
# Get logger
41
- try :
42
- from sphinx .util import logging
43
-
44
- logger = logging .getLogger (__name__ )
45
- except (ImportError , AttributeError ):
46
- # Sphinx < 1.6
47
- logger = app
48
- logger .info (bold ('fixing directory names... ' ), nonl = True )
46
+ logger = logging .getLogger (__name__ )
47
+ logger .info (bold ('fixing pathnames... ' ), nonl = True )
49
48
# Rewrite references in HTML/JS files
50
49
for dirpath , _ , filenames in os .walk (app .outdir ):
51
50
for filename in filenames :
@@ -56,6 +55,8 @@ def remove_directory_underscores(app, exception):
56
55
contents = fh .read ()
57
56
for old , new in DIRS .items ():
58
57
contents = contents .replace (old + '/' , new + '/' )
58
+ for old , new in FILES .items ():
59
+ contents = contents .replace (old , new )
59
60
with open (path , 'w' , encoding = 'utf-8' ) as fh :
60
61
fh .write (contents )
61
62
# Move directory contents
@@ -70,8 +71,14 @@ def remove_directory_underscores(app, exception):
70
71
newfile = os .path .join (newdir , filename )
71
72
os .rename (oldfile , newfile )
72
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 )
73
80
logger .info ('done' )
74
81
75
82
76
83
def setup (app ):
77
- app .connect ('build-finished' , remove_directory_underscores )
84
+ app .connect ('build-finished' , remove_path_underscores )
0 commit comments