Skip to content

Commit

Permalink
Don't overwrite a page's existing manual meta og:description tag
Browse files Browse the repository at this point in the history
  • Loading branch information
hugovk committed Oct 22, 2022
1 parent de9eccc commit 161f2b5
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 3 deletions.
2 changes: 1 addition & 1 deletion sphinxext/opengraph/__init__.py
Expand Up @@ -32,7 +32,7 @@
def make_tag(property: str, content: str, type_: str = "property") -> str:
# Parse quotation, so they won't break html tags if smart quotes are disabled
content = content.replace('"', """)
return f'<meta property="{property}" content="{content}" />'
return f'<meta {type_}="{property}" content="{content}" />'


def get_tags(
Expand Down
@@ -0,0 +1,10 @@
extensions = ["sphinxext.opengraph"]

master_doc = "index"
exclude_patterns = ["_build"]

html_theme = "basic"

ogp_site_url = "http://example.org/en/latest/"

ogp_enable_meta_description = True
@@ -0,0 +1,3 @@
:og:description: My manual og:description

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse at lorem ornare, fringilla massa nec, venenatis mi. Donec erat sapien, tincidunt nec rhoncus nec, scelerisque id diam. Orci varius natoque penatibus et magnis dis parturient mauris.
12 changes: 10 additions & 2 deletions tests/test_options.py
@@ -1,7 +1,6 @@
import pytest
from sphinx.application import Sphinx
import conftest
import os


def get_tag(tags, tag_type):
Expand Down Expand Up @@ -40,7 +39,7 @@ def test_meta_name_description(meta_tags):
assert description == og_description


@pytest.mark.sphinx("html", testroot="meta-name-description-no-override-manual")
@pytest.mark.sphinx("html", testroot="meta-name-description-manual-description")
def test_meta_name_description(meta_tags):
og_description = get_tag_content(meta_tags, "description")
description = get_meta_description(meta_tags)
Expand All @@ -49,6 +48,15 @@ def test_meta_name_description(meta_tags):
assert description == "My manual description"


@pytest.mark.sphinx("html", testroot="meta-name-description-manual-og-description")
def test_meta_name_description(meta_tags):
og_description = get_tag_content(meta_tags, "description")
description = get_meta_description(meta_tags)

assert og_description != description
assert og_description == "My manual og:description"


@pytest.mark.sphinx("html", testroot="simple")
def test_site_url(og_meta_tags):
# Uses the same directory as simple, because it already contains url for a minimal config
Expand Down

0 comments on commit 161f2b5

Please sign in to comment.