1717# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
1818#
1919
20- # Sphinx hardcodes that certain output directories have names starting with
20+ # Sphinx hardcodes that certain output paths have names starting with
2121# an underscore.
2222# Jekyll hardcodes that filenames starting with an underscore are not
2323# deployed to the website.
24- # Rename Sphinx output directories to drop the underscore.
24+ # Rename Sphinx output paths to drop the underscore.
2525
2626import os
2727
28+ from sphinx .util import logging
2829from sphinx .util .console import bold
2930
3031DIRS = {
3132 '_static' : 'static' ,
3233 '_sources' : 'sources' ,
3334}
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+ }
3439REWRITE_EXTENSIONS = {'.html' , '.js' }
3540
3641
37- def remove_directory_underscores (app , exception ):
42+ def remove_path_underscores (app , exception ):
3843 if exception :
3944 return
4045 # 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 )
4948 # Rewrite references in HTML/JS files
5049 for dirpath , _ , filenames in os .walk (app .outdir ):
5150 for filename in filenames :
@@ -56,6 +55,8 @@ def remove_directory_underscores(app, exception):
5655 contents = fh .read ()
5756 for old , new in DIRS .items ():
5857 contents = contents .replace (old + '/' , new + '/' )
58+ for old , new in FILES .items ():
59+ contents = contents .replace (old , new )
5960 with open (path , 'w' , encoding = 'utf-8' ) as fh :
6061 fh .write (contents )
6162 # Move directory contents
@@ -70,8 +71,14 @@ def remove_directory_underscores(app, exception):
7071 newfile = os .path .join (newdir , filename )
7172 os .rename (oldfile , newfile )
7273 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 )
7380 logger .info ('done' )
7481
7582
7683def setup (app ):
77- app .connect ('build-finished' , remove_directory_underscores )
84+ app .connect ('build-finished' , remove_path_underscores )
0 commit comments