Skip to content
Draft
Changes from all 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
33 changes: 29 additions & 4 deletions generator/_scripts/cfdoc_patch_header_nav.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,25 @@
import sys


def should_replace_version(version):
# always trigger for master or lts
special_versions = ["master", "lts"]

if version in special_versions:
return True

# handle numeric versions: if the version is 3.27 or higher, replace the version in the URL
# starting with 3.27 we changed the URL structure, so for older versions like 3.24
# replacing the version would lead to the 404 page. In that case, redirect to the main page.
try:
if float(version) >= 3.27:
return True
except ValueError:
return False

return False


def patch(current_branch, lts_version):
url = "https://docs.cfengine.com/docs/branches.json"
response = urllib.request.urlopen(url)
Expand All @@ -47,13 +66,19 @@ def patch(current_branch, lts_version):
):
continue
selected = ""
link = branch["Link"]
replaceVersionInLcocation = should_replace_version(branch["Version"])
if branch["Version"] == current_branch:
selected = ' selected="selected"'
link = "javascript:void(0);"
replaceVersionInLcocation = False
print(
'<a onclick="selectVersion(\'%s\')" href="#"%s>%s</a>'
% (link, selected, branch["Title"].replace("Version ", "")),
"<a onclick=\"selectVersion('%s', '%s', %s)\" href=\"#\"%s>%s</a>"
% (
branch["Version"],
current_branch,
str(replaceVersionInLcocation),
selected,
branch["Title"].replace("Version ", ""),
),
file=f,
)
print('<a href="/versions/">view all versions</a>', file=f)
Expand Down
Loading