Skip to content

Commit 6d8022e

Browse files
committed
doc: fix Jekyll hiding a JS polyfill with Sphinx 5.x
Sphinx 5.x has a temporary JS polyfill, scheduled to be removed in Sphinx 6, whose filename starts with an underscore. Therefore Jekyll doesn't publish it to the website. Rename the file and update references.
1 parent f29afe9 commit 6d8022e

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

doc/jekyll_fix.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
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

2626
import os
2727

@@ -32,15 +32,19 @@
3232
'_static': 'static',
3333
'_sources': 'sources',
3434
}
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+
}
3539
REWRITE_EXTENSIONS = {'.html', '.js'}
3640

3741

38-
def remove_directory_underscores(app, exception):
42+
def remove_path_underscores(app, exception):
3943
if exception:
4044
return
4145
# Get logger
4246
logger = logging.getLogger(__name__)
43-
logger.info(bold('fixing directory names... '), nonl=True)
47+
logger.info(bold('fixing pathnames... '), nonl=True)
4448
# Rewrite references in HTML/JS files
4549
for dirpath, _, filenames in os.walk(app.outdir):
4650
for filename in filenames:
@@ -51,6 +55,8 @@ def remove_directory_underscores(app, exception):
5155
contents = fh.read()
5256
for old, new in DIRS.items():
5357
contents = contents.replace(old + '/', new + '/')
58+
for old, new in FILES.items():
59+
contents = contents.replace(old, new)
5460
with open(path, 'w', encoding='utf-8') as fh:
5561
fh.write(contents)
5662
# Move directory contents
@@ -65,8 +71,14 @@ def remove_directory_underscores(app, exception):
6571
newfile = os.path.join(newdir, filename)
6672
os.rename(oldfile, newfile)
6773
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)
6880
logger.info('done')
6981

7082

7183
def setup(app):
72-
app.connect('build-finished', remove_directory_underscores)
84+
app.connect('build-finished', remove_path_underscores)

0 commit comments

Comments
 (0)