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

Sitemap: don't include hidden versions #11675

Merged
merged 1 commit into from
Oct 14, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/user/reference/sitemaps.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ It contains information such as:
* What translations are available for a page.

Read the Docs automatically generates a ``sitemap.xml`` for your project,
by default the sitemap includes each version of your documentation and when it was last updated,
the sitemap includes :ref:`public and not hidden versions <versions:Version states>` of your documentation and when it were last updated,
sorted by version number.

This allows search engines to prioritize results based on the version number,
Expand Down
24 changes: 23 additions & 1 deletion readthedocs/proxito/tests/test_full.py
Original file line number Diff line number Diff line change
Expand Up @@ -1554,6 +1554,17 @@ def test_sitemap_xml(self):
active=True,
type=EXTERNAL,
)

hidden_version = fixture.get(
Version,
identifier="hidden-version",
verbose_name="hidden-version",
slug="hidden-version",
privacy_level=constants.PUBLIC,
project=self.project,
active=True,
hidden=True,
)
# This also creates a Version `latest` Automatically for this project
translation = fixture.get(
Project,
Expand All @@ -1580,7 +1591,8 @@ def test_sitemap_xml(self):
self.assertEqual(response.status_code, 200)
self.assertEqual(response["Content-Type"], "application/xml")
for version in self.project.versions(manager=INTERNAL).filter(
privacy_level=constants.PUBLIC
privacy_level=constants.PUBLIC,
hidden=False,
):
self.assertContains(
response,
Expand All @@ -1598,6 +1610,16 @@ def test_sitemap_xml(self):
lang_slug=self.project.language,
),
)

# Hidden version should not appear here
self.assertNotContains(
response,
self.project.get_docs_url(
version_slug=hidden_version.slug,
lang_slug=self.project.language,
),
)

# The `translation` project doesn't have a version named `not-translated-version`
# so, the sitemap should not have a doc url for
# `not-translated-version` with `translation-es` language.
Expand Down
1 change: 1 addition & 0 deletions readthedocs/proxito/views/serve.py
Original file line number Diff line number Diff line change
Expand Up @@ -859,6 +859,7 @@ def changefreqs_generator():
public_versions = Version.internal.public(
project=project,
only_active=True,
include_hidden=False,
)
if not public_versions.exists():
raise Http404()
Expand Down
Loading