38
38
from django .views .decorators .cache import cache_page
39
39
from django .views .static import serve
40
40
41
+ from readthedocs .builds .constants import LATEST , STABLE
41
42
from readthedocs .builds .models import Version
42
43
from readthedocs .core .permissions import AdminPermission
43
44
from readthedocs .core .resolver import resolve , resolve_path
@@ -373,14 +374,14 @@ def changefreqs_generator():
373
374
"""
374
375
Generator returning ``changefreq`` needed by sitemap.xml.
375
376
376
- It returns ``daily `` on first iteration, then ``weekly `` and then it
377
+ It returns ``weekly `` on first iteration, then ``daily `` and then it
377
378
will return always ``monthly``.
378
379
379
380
We are using ``monthly`` as last value because ``never`` is too
380
381
aggressive. If the tag is removed and a branch is created with the same
381
382
name, we will want bots to revisit this.
382
383
"""
383
- changefreqs = ['daily ' , 'weekly ' ]
384
+ changefreqs = ['weekly ' , 'daily ' ]
384
385
yield from itertools .chain (changefreqs , itertools .repeat ('monthly' ))
385
386
386
387
if project .privacy_level == constants .PRIVATE :
@@ -392,6 +393,19 @@ def changefreqs_generator():
392
393
only_active = True ,
393
394
),
394
395
)
396
+
397
+ # This is a hack to swap the latest version with
398
+ # stable version to get the stable version first in the sitemap.
399
+ # We want stable with priority=1 and changefreq='weekly' and
400
+ # latest with priority=0.9 and changefreq='daily'
401
+ # More details on this: https://github.com/rtfd/readthedocs.org/issues/5447
402
+ if (
403
+ len (sorted_versions ) >= 2 and
404
+ sorted_versions [0 ].slug == LATEST and
405
+ sorted_versions [1 ].slug == STABLE
406
+ ):
407
+ sorted_versions [0 ], sorted_versions [1 ] = sorted_versions [1 ], sorted_versions [0 ]
408
+
395
409
versions = []
396
410
for version , priority , changefreq in zip (
397
411
sorted_versions ,
0 commit comments