Skip to content

Commit

Permalink
Merge pull request #22536 from brianpursley/website-22497
Browse files Browse the repository at this point in the history
Preserve relative path when switching from latest version of the documentation to an older version
  • Loading branch information
k8s-ci-robot authored Aug 26, 2020
2 parents 51eb0de + 7bc5ee0 commit 390a4d8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions layouts/404.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{{ define "main" }}
{{ partial "handle-version-switch-404.html" . }}
<div class="container-404">
<h4>
Perhaps you were looking for:
Expand Down
11 changes: 11 additions & 0 deletions layouts/partials/handle-version-switch-404.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{{/*
If a 404 occurs and the referrer is a different version of the Kubernetes documentation,
don't show the regular 404 error page, but instead redirect to the site root
*/}}
<script type="text/javascript">
var sameBaseUrlRegExp = new RegExp("^" + location.protocol + "//" + location.host.replace(".", "\\.") + "/.*", "i");
var kubernetesDocumentationUrlRegExp = new RegExp("^https?://(.+\\.)?kubernetes.io/.*", "i");
if (!sameBaseUrlRegExp.test(document.referrer) && kubernetesDocumentationUrlRegExp.test(document.referrer)) {
location.replace("/");
}
</script>
3 changes: 2 additions & 1 deletion layouts/partials/navbar-version-selector.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
{{ T "version_menu" }}
</a>
<div class="dropdown-menu dropdown-menu-right" aria-labelledby="navbarDropdownMenuLink">
{{ $p := . }}
{{ range .Site.Params.versions }}
<a class="dropdown-item" href="{{ .url }}">{{ .version }}</a>
<a class="dropdown-item" href="{{ .url }}{{ $p.RelPermalink }}">{{ .version }}</a>
{{ end }}
</div>

0 comments on commit 390a4d8

Please sign in to comment.