@@ -121,7 +121,13 @@ def minify_html_files(app, pagename, templatename, context, doctree):
121
121
def render (self , template , render_context ):
122
122
content = old_render (template , render_context )
123
123
try :
124
- return minify_html .minify (content , minify_js = True , minify_css = True )
124
+ return minify_html .minify (
125
+ content ,
126
+ minify_js = True ,
127
+ minify_css = True ,
128
+ keep_html_and_head_opening_tags = True ,
129
+ keep_closing_tags = True ,
130
+ )
125
131
except SyntaxError :
126
132
return content
127
133
@@ -168,6 +174,20 @@ def enable_dark_mode(app, config):
168
174
app .add_css_file ("dark_rtd.css" )
169
175
170
176
177
+ def rtd_config (app , config ):
178
+ """Set RTD configurations.
179
+
180
+ See https://about.readthedocs.com/blog/2024/07/addons-by-default/
181
+ """
182
+ config .html_baseurl = os .environ .get ("READTHEDOCS_CANONICAL_URL" , "" )
183
+
184
+ # Tell Jinja2 templates the build is running on Read the Docs
185
+ if os .environ .get ("READTHEDOCS" , "" ) == "True" :
186
+ if "html_context" not in config :
187
+ config .html_context = {}
188
+ config .html_context ["READTHEDOCS" ] = True
189
+
190
+
171
191
def setup (app : Sphinx ) -> Dict [str , Any ]:
172
192
# enable deepmodeling sidebar and icp
173
193
# if the repo is outside the deepmodeling, disable it
@@ -181,5 +201,6 @@ def setup(app: Sphinx) -> Dict[str, Any]:
181
201
app .connect ("build-finished" , minify_css_files )
182
202
# dark mode for rtd theme
183
203
app .connect ("config-inited" , enable_dark_mode )
204
+ app .connect ("config-inited" , rtd_config )
184
205
185
206
return {"parallel_read_safe" : True }
0 commit comments