Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sphinxext/opengraph/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def html_page_context(
context: dict[str, Any],
doctree: nodes.document,
) -> None:
if doctree:
if doctree and not app.builder.embedded:
context['metatags'] += get_tags(
context,
doctree,
Expand Down
10 changes: 4 additions & 6 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ def content(app):
return app


def _meta_tags(content, subdir=None):
def _meta_tags(content, subdir=None, target='index.html'):
if subdir is None:
c = (content.outdir / 'index.html').read_text(encoding='utf-8')
c = (content.outdir / target).read_text(encoding='utf-8')
else:
c = (content.outdir / subdir / 'index.html').read_text(encoding='utf-8')
c = (content.outdir / subdir / target).read_text(encoding='utf-8')
return BeautifulSoup(c, 'html.parser').find_all('meta')


Expand All @@ -53,9 +53,7 @@ def meta_tags(content):

@pytest.fixture
def og_meta_tags(content):
return [
tag for tag in _meta_tags(content) if tag.get('property', '').startswith('og:')
]
return _og_meta_tags(content)


@pytest.fixture
Expand Down
4 changes: 4 additions & 0 deletions tests/roots/test-simple/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@
html_theme = 'basic'

ogp_site_url = 'http://example.org/en/latest/'

# needed for ePub build
epub_copyright = 'sphinxext.opengraph team'
version = '1.0'
10 changes: 10 additions & 0 deletions tests/test_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@ def test_simple(og_meta_tags):
)


@pytest.mark.sphinx('epub', testroot='simple')
def test_epub(content: Sphinx):
"""Ogp tags are disabled for ePub build"""
meta_tags = conftest._meta_tags(content, target='index.xhtml')
og_meta_tags = [
tag for tag in meta_tags if tag.get('property', '').startswith('og:')
]
assert len(og_meta_tags) == 0


@pytest.mark.sphinx('html', testroot='meta-name-description')
def test_meta_name_description(meta_tags):
og_description = get_tag_content(meta_tags, 'description')
Expand Down
Loading