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 1 commit
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. Taken from the Sphinx `project` config value if not given.
rkdarst marked this conversation as resolved.
Show resolved Hide resolved
* `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
3 changes: 3 additions & 0 deletions sphinxext/opengraph/__init__.py
Expand Up @@ -108,6 +108,9 @@ def get_tags(
site_name = config["ogp_site_name"]
if site_name:
tags["og:site_name"] = site_name
elif config["project"]:
site_name = config["project"]
tags["og:site_name"] = config["project"]

# description tag
if description:
Expand Down
11 changes: 11 additions & 0 deletions tests/roots/test-sitename-from-project/conf.py
@@ -0,0 +1,11 @@

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.
4 changes: 4 additions & 0 deletions tests/test_options.py
Expand Up @@ -106,6 +106,10 @@ def test_description_length(og_meta_tags):
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):
Expand Down