@@ -61,7 +61,7 @@ def get_tags(
61
61
app : Sphinx ,
62
62
context : dict [str , Any ],
63
63
doctree : nodes .document ,
64
- config : dict [ str , Any ] ,
64
+ config : Config ,
65
65
) -> str :
66
66
# Get field lists for per-page overrides
67
67
fields = context ["meta" ]
@@ -77,7 +77,7 @@ def get_tags(
77
77
# Set length of description
78
78
try :
79
79
desc_len = int (
80
- fields .get ("ogp_description_length" , config [ " ogp_description_length" ] )
80
+ fields .get ("ogp_description_length" , config . ogp_description_length )
81
81
)
82
82
except ValueError :
83
83
desc_len = DEFAULT_DESCRIPTION_LENGTH
@@ -92,12 +92,12 @@ def get_tags(
92
92
tags ["og:title" ] = title
93
93
94
94
# type tag
95
- tags ["og:type" ] = config [ " ogp_type" ]
95
+ tags ["og:type" ] = config . ogp_type
96
96
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 :
99
99
# readthedocs uses ``html_baseurl`` for Sphinx > 1.8
100
- parse_result = urlsplit (config [ " html_baseurl" ] )
100
+ parse_result = urlsplit (config . html_baseurl )
101
101
else :
102
102
# readthedocs addons no longer configures ``html_baseurl``
103
103
if rtd_canonical_url := os .getenv ("READTHEDOCS_CANONICAL_URL" ):
@@ -106,7 +106,7 @@ def get_tags(
106
106
raise OSError ("ReadTheDocs did not provide a valid canonical URL!" )
107
107
108
108
# Grab root url from canonical url
109
- config [ " ogp_site_url" ] = urlunparse (
109
+ config . ogp_site_url = urlunparse (
110
110
(
111
111
parse_result .scheme ,
112
112
parse_result .netloc ,
@@ -120,26 +120,26 @@ def get_tags(
120
120
# url tag
121
121
# Get the URL of the specific page
122
122
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" ])
124
124
)
125
125
tags ["og:url" ] = page_url
126
126
127
127
# site name tag, False disables, default to project if ogp_site_name not
128
128
# set.
129
- if config [ " ogp_site_name" ] is False :
129
+ if config . ogp_site_name is False :
130
130
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
133
133
else :
134
- site_name = config [ " ogp_site_name" ]
134
+ site_name = config . ogp_site_name
135
135
if site_name :
136
136
tags ["og:site_name" ] = site_name
137
137
138
138
# description tag
139
139
if description :
140
140
tags ["og:description" ] = description
141
141
142
- if config [ " ogp_enable_meta_description" ] and not get_meta_description (
142
+ if config . ogp_enable_meta_description and not get_meta_description (
143
143
context ["metatags" ]
144
144
):
145
145
meta_tags ["description" ] = description
@@ -152,15 +152,15 @@ def get_tags(
152
152
ogp_image_alt = fields .get ("og:image:alt" )
153
153
fields .pop ("og:image" , None )
154
154
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 )
158
158
159
159
# Decide whether to add social media card images for each page.
160
160
# Only do this as a fallback if the user hasn't given any configuration
161
161
# to add other images.
162
162
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 {}
164
164
config_social .update (social_card_user_options )
165
165
if (
166
166
not (image_url or ogp_use_first_image )
@@ -175,7 +175,7 @@ def get_tags(
175
175
pagename = context ["pagename" ],
176
176
srcdir = app .srcdir ,
177
177
outdir = app .outdir ,
178
- config = app . config ,
178
+ config = config ,
179
179
env = app .env ,
180
180
)
181
181
ogp_use_first_image = False
@@ -219,7 +219,7 @@ def get_tags(
219
219
else : # ogp_image is set
220
220
# ogp_image is defined as being relative to the site root.
221
221
# This workaround is to keep that functionality from breaking.
222
- root = config [ " ogp_site_url" ]
222
+ root = config . ogp_site_url
223
223
224
224
image_url = urljoin (root , image_url_parsed .path )
225
225
tags ["og:image" ] = image_url
@@ -239,7 +239,7 @@ def get_tags(
239
239
"\n " .join (
240
240
[make_tag (p , c ) for p , c in tags .items ()]
241
241
+ [make_tag (p , c , "name" ) for p , c in meta_tags .items ()]
242
- + config [ " ogp_custom_meta_tags" ]
242
+ + config . ogp_custom_meta_tags
243
243
)
244
244
+ "\n "
245
245
)
0 commit comments