diff --git a/docs/source/conf.py b/docs/source/conf.py
index ee638f3..05cc84d 100644
--- a/docs/source/conf.py
+++ b/docs/source/conf.py
@@ -44,6 +44,8 @@
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = []
+# Generate tags.
+enable_meta_description = True
# -- Options for HTML output -------------------------------------------------
diff --git a/sphinxext/opengraph/__init__.py b/sphinxext/opengraph/__init__.py
index e955b22..2832f6a 100644
--- a/sphinxext/opengraph/__init__.py
+++ b/sphinxext/opengraph/__init__.py
@@ -28,10 +28,10 @@
}
-def make_tag(property: str, content: str) -> str:
+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'\n '
+ return f'\n '
def get_tags(
@@ -104,6 +104,10 @@ def get_tags(
# description tag
if description:
tags["og:description"] = description
+ if config["enable_meta_description"]:
+ config["ogp_custom_meta_tags"].append(
+ make_tag("description", description, "name")
+ )
# image tag
# Get basic values from config
@@ -183,6 +187,7 @@ def setup(app: Sphinx) -> Dict[str, Any]:
app.add_config_value("ogp_type", "website", "html")
app.add_config_value("ogp_site_name", None, "html")
app.add_config_value("ogp_custom_meta_tags", [], "html")
+ app.add_config_value("enable_meta_description", False, "html")
app.connect("html-page-context", html_page_context)
diff --git a/tests/roots/test-meta-name-description/conf.py b/tests/roots/test-meta-name-description/conf.py
new file mode 100644
index 0000000..b31eaac
--- /dev/null
+++ b/tests/roots/test-meta-name-description/conf.py
@@ -0,0 +1,10 @@
+extensions = ["sphinxext.opengraph"]
+
+master_doc = "index"
+exclude_patterns = ["_build"]
+
+html_theme = "basic"
+
+ogp_site_url = "http://example.org/en/latest/"
+
+enable_meta_description = True
diff --git a/tests/roots/test-meta-name-description/index.rst b/tests/roots/test-meta-name-description/index.rst
new file mode 100644
index 0000000..a33871d
--- /dev/null
+++ b/tests/roots/test-meta-name-description/index.rst
@@ -0,0 +1 @@
+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.
\ No newline at end of file
diff --git a/tests/test_options.py b/tests/test_options.py
index 06ad32e..9f31ea6 100644
--- a/tests/test_options.py
+++ b/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):
@@ -26,6 +25,16 @@ def test_simple(og_meta_tags):
)
+@pytest.mark.sphinx("html", testroot="meta-name-description")
+def test_meta_name_description(meta_tags):
+ og_description = get_tag_content(meta_tags, "description")
+ description = [tag for tag in meta_tags if tag.get("name") == "description"][0].get(
+ "content", ""
+ )
+
+ assert og_description == 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