@@ -142,21 +142,28 @@ def _create_badge_link(link):
142
142
sg_note = soup .find ("div" , class_ = "sphx-glr-download-link-note" )
143
143
sg_footer = soup .find ("div" , class_ = "sphx-glr-footer" )
144
144
145
+ # If any one of these two is not found, we directly give up tweaking
146
+ if sg_note is None or sg_footer is None :
147
+ continue
148
+
145
149
# Move the download links into the secondary sidebar
146
- py_link = sg_footer .find ("div" , class_ = "sphx-glr-download-python" ). a
147
- ipy_link = sg_footer .find ("div" , class_ = "sphx-glr-download-jupyter" ). a
150
+ py_link_div = sg_footer .find ("div" , class_ = "sphx-glr-download-python" )
151
+ ipy_link_div = sg_footer .find ("div" , class_ = "sphx-glr-download-jupyter" )
148
152
_create_secondary_sidebar_component (
149
153
[
150
- _create_download_link (py_link , is_jupyter = False ),
151
- _create_download_link (ipy_link , is_jupyter = True ),
154
+ _create_download_link (py_link_div . a , is_jupyter = False ),
155
+ _create_download_link (ipy_link_div . a , is_jupyter = True ),
152
156
]
153
157
)
154
158
155
159
# Move the badge links into the secondary sidebar
156
- lite_link = sg_footer .find ("div" , class_ = "lite-badge" ). a
157
- binder_link = sg_footer .find ("div" , class_ = "binder-badge" ). a
160
+ lite_link_div = sg_footer .find ("div" , class_ = "lite-badge" )
161
+ binder_link_div = sg_footer .find ("div" , class_ = "binder-badge" )
158
162
_create_secondary_sidebar_component (
159
- [_create_badge_link (lite_link ), _create_badge_link (binder_link )]
163
+ [
164
+ _create_badge_link (lite_link_div .a ),
165
+ _create_badge_link (binder_link_div .a ),
166
+ ]
160
167
)
161
168
162
169
# Remove the sourcelink component from the secondary sidebar; the reason
@@ -171,9 +178,8 @@ def _create_badge_link(link):
171
178
sg_note .extract ()
172
179
sg_footer .extract ()
173
180
174
- except Exception as e :
181
+ except Exception :
175
182
# If any step fails we directly skip the file
176
- logger .warning (f"Failed to tweak gallery links in { html_file } : { e } " )
177
183
continue
178
184
179
185
# Write the modified file back
0 commit comments