2525import sys
2626
2727
28+ def should_replace_version (version ):
29+ # always trigger for master or lts
30+ special_versions = ["master" , "lts" ]
31+
32+ if version in special_versions :
33+ return True
34+
35+ # handle numeric versions: if the version is 3.27 or higher, replace the version in the URL
36+ # starting with 3.27 we changed the URL structure, so for older versions like 3.24
37+ # replacing the version would lead to the 404 page. In that case, redirect to the main page.
38+ try :
39+ if float (version ) >= 3.27 :
40+ return True
41+ except ValueError :
42+ return False
43+
44+ return False
45+
46+
2847def patch (current_branch , lts_version ):
2948 url = "https://docs.cfengine.com/docs/branches.json"
3049 response = urllib .request .urlopen (url )
@@ -48,12 +67,20 @@ def patch(current_branch, lts_version):
4867 continue
4968 selected = ""
5069 link = branch ["Link" ]
70+ replaceVersionInLcocation = should_replace_version (branch ["Version" ])
5171 if branch ["Version" ] == current_branch :
5272 selected = ' selected="selected"'
5373 link = "javascript:void(0);"
74+ replaceVersionInLcocation = False
5475 print (
55- '<a onclick="selectVersion(\' %s\' )" href="#"%s>%s</a>'
56- % (link , selected , branch ["Title" ].replace ("Version " , "" )),
76+ "<a onclick=\" selectVersion('%s', '/docs/%s/', %s)\" href=\" #\" %s>%s</a>"
77+ % (
78+ link ,
79+ current_branch ,
80+ str (replaceVersionInLcocation ).lower (),
81+ selected ,
82+ branch ["Title" ].replace ("Version " , "" ),
83+ ),
5784 file = f ,
5885 )
5986 print ('<a href="/versions/">view all versions</a>' , file = f )
0 commit comments