@@ -61,7 +61,7 @@ def get_tags(
6161 app : Sphinx ,
6262 context : dict [str , Any ],
6363 doctree : nodes .document ,
64- config : dict [ str , Any ] ,
64+ config : Config ,
6565) -> str :
6666 # Get field lists for per-page overrides
6767 fields = context ["meta" ]
@@ -77,7 +77,7 @@ def get_tags(
7777 # Set length of description
7878 try :
7979 desc_len = int (
80- fields .get ("ogp_description_length" , config [ " ogp_description_length" ] )
80+ fields .get ("ogp_description_length" , config . ogp_description_length )
8181 )
8282 except ValueError :
8383 desc_len = DEFAULT_DESCRIPTION_LENGTH
@@ -92,12 +92,12 @@ def get_tags(
9292 tags ["og:title" ] = title
9393
9494 # type tag
95- tags ["og:type" ] = config [ " ogp_type" ]
95+ tags ["og:type" ] = config . ogp_type
9696
97- if not config [ " ogp_site_url" ] and os .getenv ("READTHEDOCS" ):
98- if config [ " html_baseurl" ] is not None :
97+ if not config . ogp_site_url and os .getenv ("READTHEDOCS" ):
98+ if config . html_baseurl is not None :
9999 # readthedocs uses ``html_baseurl`` for Sphinx > 1.8
100- parse_result = urlsplit (config [ " html_baseurl" ] )
100+ parse_result = urlsplit (config . html_baseurl )
101101 else :
102102 # readthedocs addons no longer configures ``html_baseurl``
103103 if rtd_canonical_url := os .getenv ("READTHEDOCS_CANONICAL_URL" ):
@@ -106,7 +106,7 @@ def get_tags(
106106 raise OSError ("ReadTheDocs did not provide a valid canonical URL!" )
107107
108108 # Grab root url from canonical url
109- config [ " ogp_site_url" ] = urlunparse (
109+ config . ogp_site_url = urlunparse (
110110 (
111111 parse_result .scheme ,
112112 parse_result .netloc ,
@@ -120,26 +120,26 @@ def get_tags(
120120 # url tag
121121 # Get the URL of the specific page
122122 page_url = urljoin (
123- config [ " ogp_site_url" ] , app .builder .get_target_uri (context ["pagename" ])
123+ config . ogp_site_url , app .builder .get_target_uri (context ["pagename" ])
124124 )
125125 tags ["og:url" ] = page_url
126126
127127 # site name tag, False disables, default to project if ogp_site_name not
128128 # set.
129- if config [ " ogp_site_name" ] is False :
129+ if config . ogp_site_name is False :
130130 site_name = None
131- elif config [ " ogp_site_name" ] is None :
132- site_name = config [ " project" ]
131+ elif config . ogp_site_name is None :
132+ site_name = config . project
133133 else :
134- site_name = config [ " ogp_site_name" ]
134+ site_name = config . ogp_site_name
135135 if site_name :
136136 tags ["og:site_name" ] = site_name
137137
138138 # description tag
139139 if description :
140140 tags ["og:description" ] = description
141141
142- if config [ " ogp_enable_meta_description" ] and not get_meta_description (
142+ if config . ogp_enable_meta_description and not get_meta_description (
143143 context ["metatags" ]
144144 ):
145145 meta_tags ["description" ] = description
@@ -152,15 +152,15 @@ def get_tags(
152152 ogp_image_alt = fields .get ("og:image:alt" )
153153 fields .pop ("og:image" , None )
154154 else :
155- image_url = config [ " ogp_image" ]
156- ogp_use_first_image = config [ " ogp_use_first_image" ]
157- ogp_image_alt = fields .get ("og:image:alt" , config [ " ogp_image_alt" ] )
155+ image_url = config . ogp_image
156+ ogp_use_first_image = config . ogp_use_first_image
157+ ogp_image_alt = fields .get ("og:image:alt" , config . ogp_image_alt )
158158
159159 # Decide whether to add social media card images for each page.
160160 # Only do this as a fallback if the user hasn't given any configuration
161161 # to add other images.
162162 config_social = DEFAULT_SOCIAL_CONFIG .copy ()
163- social_card_user_options = app . config .ogp_social_cards or {}
163+ social_card_user_options = config .ogp_social_cards or {}
164164 config_social .update (social_card_user_options )
165165 if (
166166 not (image_url or ogp_use_first_image )
@@ -175,7 +175,7 @@ def get_tags(
175175 pagename = context ["pagename" ],
176176 srcdir = app .srcdir ,
177177 outdir = app .outdir ,
178- config = app . config ,
178+ config = config ,
179179 env = app .env ,
180180 )
181181 ogp_use_first_image = False
@@ -219,7 +219,7 @@ def get_tags(
219219 else : # ogp_image is set
220220 # ogp_image is defined as being relative to the site root.
221221 # This workaround is to keep that functionality from breaking.
222- root = config [ " ogp_site_url" ]
222+ root = config . ogp_site_url
223223
224224 image_url = urljoin (root , image_url_parsed .path )
225225 tags ["og:image" ] = image_url
@@ -239,7 +239,7 @@ def get_tags(
239239 "\n " .join (
240240 [make_tag (p , c ) for p , c in tags .items ()]
241241 + [make_tag (p , c , "name" ) for p , c in meta_tags .items ()]
242- + config [ " ogp_custom_meta_tags" ]
242+ + config . ogp_custom_meta_tags
243243 )
244244 + "\n "
245245 )
0 commit comments