|
12 | 12 | from sphinxext.opengraph._meta_parser import get_meta_description |
13 | 13 | from sphinxext.opengraph._title_parser import get_title |
14 | 14 |
|
| 15 | +try: |
| 16 | + from types import NoneType |
| 17 | +except ImportError: |
| 18 | + NoneType = type(None) |
| 19 | + |
15 | 20 | if TYPE_CHECKING: |
16 | 21 | from typing import Any |
17 | 22 |
|
@@ -326,17 +331,32 @@ def make_tag(property: str, content: str, type_: str = 'property') -> str: |
326 | 331 | def setup(app: Sphinx) -> ExtensionMetadata: |
327 | 332 | # ogp_site_url="" allows relative by default, even though it's not |
328 | 333 | # officially supported by OGP. |
329 | | - app.add_config_value('ogp_site_url', '', 'html') |
330 | | - app.add_config_value('ogp_canonical_url', '', 'html') |
331 | | - app.add_config_value('ogp_description_length', DEFAULT_DESCRIPTION_LENGTH, 'html') |
332 | | - app.add_config_value('ogp_image', None, 'html') |
333 | | - app.add_config_value('ogp_image_alt', None, 'html') |
334 | | - app.add_config_value('ogp_use_first_image', False, 'html') |
335 | | - app.add_config_value('ogp_type', 'website', 'html') |
336 | | - app.add_config_value('ogp_site_name', None, 'html') |
337 | | - app.add_config_value('ogp_social_cards', None, 'html') |
338 | | - app.add_config_value('ogp_custom_meta_tags', (), 'html') |
339 | | - app.add_config_value('ogp_enable_meta_description', True, 'html') |
| 334 | + app.add_config_value('ogp_site_url', '', 'html', types=frozenset({str})) |
| 335 | + app.add_config_value('ogp_canonical_url', '', 'html', types=frozenset({str})) |
| 336 | + app.add_config_value( |
| 337 | + 'ogp_description_length', |
| 338 | + DEFAULT_DESCRIPTION_LENGTH, |
| 339 | + 'html', |
| 340 | + types=frozenset({int}), |
| 341 | + ) |
| 342 | + app.add_config_value('ogp_image', None, 'html', types=frozenset({str, NoneType})) |
| 343 | + app.add_config_value( |
| 344 | + 'ogp_image_alt', None, 'html', types=frozenset({str, bool, NoneType}) |
| 345 | + ) |
| 346 | + app.add_config_value('ogp_use_first_image', False, 'html', types=frozenset({bool})) |
| 347 | + app.add_config_value('ogp_type', 'website', 'html', types=frozenset({str})) |
| 348 | + app.add_config_value( |
| 349 | + 'ogp_site_name', None, 'html', types=frozenset({str, bool, NoneType}) |
| 350 | + ) |
| 351 | + app.add_config_value( |
| 352 | + 'ogp_social_cards', None, 'html', types=frozenset({dict, NoneType}) |
| 353 | + ) |
| 354 | + app.add_config_value( |
| 355 | + 'ogp_custom_meta_tags', (), 'html', types=frozenset({list, tuple}) |
| 356 | + ) |
| 357 | + app.add_config_value( |
| 358 | + 'ogp_enable_meta_description', True, 'html', types=frozenset({bool}) |
| 359 | + ) |
340 | 360 |
|
341 | 361 | # Main Sphinx OpenGraph linking |
342 | 362 | app.connect('html-page-context', html_page_context) |
|
0 commit comments