Skip to content

Sitemap sort order priorities updated #5724

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

Merged
merged 8 commits into from
Jun 17, 2019
Merged
Show file tree
Hide file tree
Changes from 6 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
17 changes: 15 additions & 2 deletions readthedocs/core/views/serve.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
from django.views.decorators.cache import cache_page
from django.views.static import serve

from readthedocs.builds.constants import LATEST, STABLE
from readthedocs.builds.models import Version
from readthedocs.core.permissions import AdminPermission
from readthedocs.core.resolver import resolve, resolve_path
Expand Down Expand Up @@ -369,14 +370,14 @@ def changefreqs_generator():
"""
Generator returning ``changefreq`` needed by sitemap.xml.

It returns ``daily`` on first iteration, then ``weekly`` and then it
It returns ``weekly`` on first iteration, then ``daily`` and then it
will return always ``monthly``.

We are using ``monthly`` as last value because ``never`` is too
aggressive. If the tag is removed and a branch is created with the same
name, we will want bots to revisit this.
"""
changefreqs = ['daily', 'weekly']
changefreqs = ['weekly', 'daily']
yield from itertools.chain(changefreqs, itertools.repeat('monthly'))

if project.privacy_level == constants.PRIVATE:
Expand All @@ -388,6 +389,18 @@ def changefreqs_generator():
only_active=True,
),
)

# This is a hack to swap the latest version with
# stable version to get the stable version first in the sitemap.
# We want stable with priority=1 and changefreq='weekly' and
# latest with priority=0.9 and changefreq='daily'
# More details on this: https://github.com/rtfd/readthedocs.org/issues/5447
if (
sorted_versions[0].slug == LATEST and
sorted_versions[1].slug == STABLE
):
sorted_versions[0], sorted_versions[1] = sorted_versions[1], sorted_versions[0]

versions = []
for version, priority, changefreq in zip(
sorted_versions,
Expand Down
33 changes: 32 additions & 1 deletion readthedocs/rtd_tests/tests/test_doc_serving.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,15 @@ def test_sitemap_xml(self):
project=self.public,
active=True
)
stable_version = fixture.get(
Version,
identifier='stable',
verbose_name='stable',
slug='stable',
privacy_level=constants.PUBLIC,
project=self.public,
active=True
)
# This also creates a Version `latest` Automatically for this project
translation = fixture.get(
Project,
Expand Down Expand Up @@ -269,7 +278,7 @@ def test_sitemap_xml(self):
),
)

# stable is marked as PRIVATE and should not appear here
# PRIVATE version should not appear here
self.assertNotContains(
response,
self.public.get_docs_url(
Expand All @@ -293,3 +302,25 @@ def test_sitemap_xml(self):
# hreflang should use hyphen instead of underscore
# in language and country value. (zh_CN should be zh-CN)
self.assertContains(response, 'zh-CN')

# Check if STABLE version has 'priority of 1 and changefreq of weekly.
self.assertEqual(
response.context['versions'][0]['loc'],
self.public.get_docs_url(
version_slug=stable_version.slug,
lang_slug=self.public.language,
private=False,
),)
self.assertEqual(response.context['versions'][0]['priority'], 1)
self.assertEqual(response.context['versions'][0]['changefreq'], 'weekly')

# Check if LATEST version has priority of 0.9 and changefreq of daily.
self.assertEqual(
response.context['versions'][1]['loc'],
self.public.get_docs_url(
version_slug='latest',
lang_slug=self.public.language,
private=False,
),)
self.assertEqual(response.context['versions'][1]['priority'], 0.9)
self.assertEqual(response.context['versions'][1]['changefreq'], 'daily')