Skip to content

Commit 7469f2b

Browse files
authored
Take default og:site_name from sphinx project config value (#83)
1 parent fc41303 commit 7469f2b

File tree

5 files changed

+24
-3
lines changed

5 files changed

+24
-3
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Users hosting documentation on Read The Docs *do not* need to set any of the fol
2929
* `ogp_description_length`
3030
* Configure the amount of characters taken from a page. The default of 200 is probably good for most people. If something other than a number is used, it defaults back to 200.
3131
* `ogp_site_name`
32-
* This is not required. Name of the site. This is displayed above the title.
32+
* This is not required. Name of the site. This is displayed above the title. Defaults to the Sphinx [`project`](https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-project) config value. Set to `False` to unset and use no default.
3333
* `ogp_image`
3434
* This is not required. Link to image to show. Note that all relative paths are converted to be relative to the root of the html output as defined by `ogp_site_url`.
3535
* `ogp_image_alt`

sphinxext/opengraph/__init__.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,14 @@ def get_tags(
104104
)
105105
tags["og:url"] = page_url
106106

107-
# site name tag
108-
site_name = config["ogp_site_name"]
107+
# site name tag, False disables, default to project if ogp_site_name not
108+
# set.
109+
if config["ogp_site_name"] is False:
110+
site_name = None
111+
elif config["ogp_site_name"] is None:
112+
site_name = config["project"]
113+
else:
114+
site_name = config["ogp_site_name"]
109115
if site_name:
110116
tags["og:site_name"] = site_name
111117

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
extensions = ["sphinxext.opengraph"]
2+
3+
project = "Project name"
4+
master_doc = "index"
5+
exclude_patterns = ["_build"]
6+
7+
html_theme = "basic"
8+
9+
ogp_site_url = "http://example.org/en/latest/"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
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.

tests/test_options.py

+5
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,11 @@ def test_site_name(og_meta_tags):
107107
assert get_tag_content(og_meta_tags, "site_name") == "Example's Docs!"
108108

109109

110+
@pytest.mark.sphinx("html", testroot="sitename-from-project")
111+
def test_site_name_project(og_meta_tags):
112+
assert get_tag_content(og_meta_tags, "site_name") == "Project name"
113+
114+
110115
@pytest.mark.sphinx("html", testroot="first-image")
111116
def test_first_image(og_meta_tags):
112117
assert (

0 commit comments

Comments
 (0)