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 sort order priorities updated #5724

Merged
merged 8 commits into from
Jun 17, 2019
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions readthedocs/core/views/serve.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,14 +369,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 Down
10 changes: 5 additions & 5 deletions readthedocs/projects/version_handling.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,23 +43,23 @@ def comparable_version(version_string):
"""
Can be used as ``key`` argument to ``sorted``.

The ``LATEST`` version shall always beat other versions in comparison.
``STABLE`` should be listed second. If we cannot figure out the version
The ``STABLE`` version shall always beat other versions in comparison.
``LATEST`` should be listed second. If we cannot figure out the version
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we want to make this change here (in this function) since it will affect more places than just the sitemap_xml view.

number then we sort it to the bottom of the list.

:param version_string: version as string object (e.g. '3.10.1' or 'latest')
:type version_string: str or unicode

:returns: a comparable version object (e.g. 'latest' -> Version('99999.0'))
:returns: a comparable version object (e.g. 'latest' -> Version('9999.0'))

:rtype: packaging.version.Version
"""
comparable = parse_version_failsafe(version_string)
if not comparable:
if version_string == LATEST_VERBOSE_NAME:
comparable = Version('99999.0')
elif version_string == STABLE_VERBOSE_NAME:
comparable = Version('9999.0')
elif version_string == STABLE_VERBOSE_NAME:
comparable = Version('99999.0')
else:
comparable = Version('0.01')
return comparable
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')