Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Take default og:site_name from sphinx project config value #83

Merged
merged 5 commits into from Nov 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -29,7 +29,7 @@ Users hosting documentation on Read The Docs *do not* need to set any of the fol
* `ogp_description_length`
* 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.
* `ogp_site_name`
* This is not required. Name of the site. This is displayed above the title.
* 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.
* `ogp_image`
* 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`.
* `ogp_image_alt`
Expand Down
10 changes: 8 additions & 2 deletions sphinxext/opengraph/__init__.py
Expand Up @@ -104,8 +104,14 @@ def get_tags(
)
tags["og:url"] = page_url

# site name tag
site_name = config["ogp_site_name"]
# site name tag, False disables, default to project if ogp_site_name not
# set.
if config["ogp_site_name"] is False:
site_name = None
elif config["ogp_site_name"] is None:
site_name = config["project"]
else:
site_name = config["ogp_site_name"]
if site_name:
tags["og:site_name"] = site_name

Expand Down
9 changes: 9 additions & 0 deletions tests/roots/test-sitename-from-project/conf.py
@@ -0,0 +1,9 @@
extensions = ["sphinxext.opengraph"]

project = "Project name"
master_doc = "index"
exclude_patterns = ["_build"]

html_theme = "basic"

ogp_site_url = "http://example.org/en/latest/"
1 change: 1 addition & 0 deletions tests/roots/test-sitename-from-project/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.
5 changes: 5 additions & 0 deletions tests/test_options.py
Expand Up @@ -107,6 +107,11 @@ def test_site_name(og_meta_tags):
assert get_tag_content(og_meta_tags, "site_name") == "Example's Docs!"


@pytest.mark.sphinx("html", testroot="sitename-from-project")
def test_site_name_project(og_meta_tags):
assert get_tag_content(og_meta_tags, "site_name") == "Project name"


@pytest.mark.sphinx("html", testroot="first-image")
def test_first_image(og_meta_tags):
assert (
Expand Down