Skip to content

Commit fd86b2f

Browse files
committed
Add arbitrary tags support
1 parent a72b254 commit fd86b2f

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

sphinxext/opengraph/__init__.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,15 @@ def make_tag(property: str, content: str) -> str:
3434
return f'<meta property="{property}" content="{content}" />\n '
3535

3636

37+
def make_arbitrary_tags(fields: Dict[str, Any]) -> str:
38+
tags = ""
39+
for name, content in fields.items():
40+
if name.startswith("og:"):
41+
tags += make_tag(name, content)
42+
43+
return tags
44+
45+
3746
def get_tags(
3847
app: Sphinx,
3948
context: Dict[str, Any],
@@ -141,24 +150,22 @@ def get_tags(
141150
elif ogp_image_alt is None and title:
142151
tags += make_tag("og:image:alt", title)
143152

153+
# arbitrary tags
154+
tags += make_arbitrary_tags(fields)
155+
144156
# custom tags
145157
tags += "\n".join(config["ogp_custom_meta_tags"])
146158

147159
return tags
148160

149161

150-
from sphinx.util import logging
151-
152-
153162
def html_page_context(
154163
app: Sphinx,
155164
pagename: str,
156165
templatename: str,
157166
context: Dict[str, Any],
158167
doctree: nodes.document,
159168
) -> None:
160-
logger = logging.getLogger(__name__)
161-
logger.info(context.get("meta"))
162169
if doctree:
163170
context["metatags"] += get_tags(app, context, doctree, app.config)
164171

0 commit comments

Comments
 (0)