@@ -1040,31 +1040,30 @@ def get_output_path(self, page_name: str, /) -> Path:
1040
1040
def get_outfilename (self , pagename : str ) -> _StrPath :
1041
1041
return _StrPath (self .get_output_path (pagename ))
1042
1042
1043
- def add_sidebars (self , pagename : str , ctx : dict [str , Any ]) -> None :
1044
- def has_wildcard (pattern : str ) -> bool :
1045
- return any (char in pattern for char in '*?[' )
1046
-
1043
+ def _get_sidebars (self , pagename : str , / ) -> tuple [str , ...]:
1047
1044
matched = None
1048
1045
1049
1046
# default sidebars settings for selected theme
1050
- sidebars = list ( self .theme .sidebar_templates )
1047
+ sidebars = self .theme .sidebar_templates
1051
1048
1052
1049
# user sidebar settings
1053
1050
html_sidebars = self .get_builder_config ('sidebars' , 'html' )
1054
1051
msg = __ ('page %s matches two patterns in html_sidebars: %r and %r' )
1055
1052
for pattern , pat_sidebars in html_sidebars .items ():
1056
1053
if patmatch (pagename , pattern ):
1057
- if matched and has_wildcard (pattern ):
1054
+ if matched and _has_wildcard (pattern ):
1058
1055
# warn if both patterns contain wildcards
1059
- if has_wildcard (matched ):
1056
+ if _has_wildcard (matched ):
1060
1057
logger .warning (msg , pagename , matched , pattern )
1061
1058
# else the already matched pattern is more specific
1062
1059
# than the present one, because it contains no wildcard
1063
1060
continue
1064
1061
matched = pattern
1065
- sidebars = pat_sidebars
1062
+ sidebars = tuple (pat_sidebars )
1063
+ return sidebars
1066
1064
1067
- ctx ['sidebars' ] = list (sidebars )
1065
+ def add_sidebars (self , pagename : str , ctx : dict [str , Any ]) -> None :
1066
+ ctx ['sidebars' ] = list (self ._get_sidebars (pagename ))
1068
1067
1069
1068
# --------- these are overwritten by the serialization builder
1070
1069
@@ -1123,7 +1122,7 @@ def hasdoc(name: str) -> bool:
1123
1122
ctx ['hasdoc' ] = hasdoc
1124
1123
1125
1124
ctx ['toctree' ] = lambda ** kwargs : self ._get_local_toctree (pagename , ** kwargs )
1126
- self .add_sidebars (pagename , ctx )
1125
+ ctx [ 'sidebars' ] = list ( self ._get_sidebars (pagename ) )
1127
1126
ctx .update (addctx )
1128
1127
1129
1128
# 'blah.html' should have content_root = './' not ''.
@@ -1292,6 +1291,10 @@ def dump_search_index(self) -> None:
1292
1291
Path (search_index_tmp ).replace (search_index_path )
1293
1292
1294
1293
1294
+ def _has_wildcard (pattern : str , / ) -> bool :
1295
+ return any (char in pattern for char in '*?[' )
1296
+
1297
+
1295
1298
def convert_html_css_files (app : Sphinx , config : Config ) -> None :
1296
1299
"""Convert string styled html_css_files to tuple styled one."""
1297
1300
html_css_files : list [tuple [str , dict [str , str ]]] = []
0 commit comments