Skip to content

Commit

Permalink
Sitemap: don't include hidden versions (#11675)
Browse files Browse the repository at this point in the history
Closes #11584
  • Loading branch information
stsewd authored Oct 14, 2024
1 parent d0baa8e commit ca9b658
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
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

0 comments on commit ca9b658

Please sign in to comment.