Skip to content

Commit 0f3e4a8

Browse files
committed
Prevent creation of multiple tags with the same property
1 parent 13fb48a commit 0f3e4a8

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

sphinxext/opengraph/__init__.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,16 @@
2626
"heif": "image/heif",
2727
"tiff": "image/tiff",
2828
}
29+
TAG_LIST = []
2930

3031

3132
def make_tag(property: str, content: str) -> str:
3233
# Parse quotation, so they won't break html tags if smart quotes are disabled
33-
content = content.replace('"', """)
34-
return f'<meta property="{property}" content="{content}" />\n '
34+
if property not in TAG_LIST:
35+
TAG_LIST.append(property)
36+
content = content.replace('"', "&quot;")
37+
return f'<meta property="{property}" content="{content}" />\n '
38+
return ""
3539

3640

3741
def make_arbitrary_tags(fields: Dict[str, Any]) -> str:
@@ -49,6 +53,7 @@ def get_tags(
4953
doctree: nodes.document,
5054
config: Dict[str, Any],
5155
) -> str:
56+
TAG_LIST.clear()
5257
# Get field lists for per-poge overrides
5358
fields = context["meta"]
5459
if fields is None:
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
:og:video: http://example.org/video.mp4
22
:og:video:type: video/mp4
3+
:og:url: http://example.com/
34

45
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.

tests/test_options.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,8 @@ def test_overrides_complex(og_meta_tags):
184184
def test_arbitrary_tags(og_meta_tags):
185185
assert get_tag_content(og_meta_tags, "video") == "http://example.org/video.mp4"
186186
assert get_tag_content(og_meta_tags, "video:type") == "video/mp4"
187+
assert get_tag_content(og_meta_tags, "url") == "http://example.org/index.html"
188+
assert len([tag for tag in og_meta_tags if tag.get("property") == "og:url"]) == 1
187189

188190

189191
# use same as simple, as configuration is identical to overriden

0 commit comments

Comments
 (0)