Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions sphinxext/opengraph/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,24 @@ def get_tags(
tags['og:site_name'] = site_name

# description tag
if description:
og_description = fields.get('og:description')
if og_description:
tags['og:description'] = og_description
if description and not og_description:
tags['og:description'] = description

if config.ogp_enable_meta_description and not get_meta_description(
context['metatags']
):
meta_tags['description'] = description
# Check for meta description override
meta_description_exists = get_meta_description(context['metatags'])
if og_description and not meta_description_exists:
meta_tags['description'] = og_description
elif (
config.ogp_enable_meta_description
and not meta_description_exists
and description
and not og_description
and getattr(config, 'ogp_copy_og_description_to_meta', False)
):
meta_tags['description'] = description

# image tag
# Get basic values from config
Expand Down Expand Up @@ -357,6 +368,9 @@ def setup(app: Sphinx) -> ExtensionMetadata:
app.add_config_value(
'ogp_enable_meta_description', True, 'html', types=frozenset({bool})
)
app.add_config_value(
'ogp_copy_og_description_to_meta', False, 'html', types=frozenset({bool})
)

# Main Sphinx OpenGraph linking
app.connect('html-page-context', html_page_context)
Expand Down
Loading