|
16 | 16 |
|
17 | 17 | {{- $changeLanguage := (T "changeVersion") | default "Change version" -}} |
18 | 18 |
|
| 19 | +{{- /* Rhize: work out the current page's path within its version tree, so |
| 20 | + switching versions can try to land on the same page in the target |
| 21 | + version instead of always going to that version's homepage. */ -}} |
| 22 | +{{- $pageURL := page.RelPermalink -}} |
| 23 | +{{- $pathSegments := strings.Split (strings.Trim $pageURL "/") "/" -}} |
| 24 | +{{- $relPath := "" -}} |
| 25 | +{{- if and (ge (len $pathSegments) 2) (eq (index $pathSegments 0) "versions") -}} |
| 26 | + {{- $relPath = delimit (after 2 $pathSegments) "/" -}} |
| 27 | +{{- else if and (ge (len $pathSegments) 1) (eq (index $pathSegments 0) "latest") -}} |
| 28 | + {{- $relPath = delimit (after 1 $pathSegments) "/" -}} |
| 29 | +{{- else -}} |
| 30 | + {{- $relPath = delimit $pathSegments "/" -}} |
| 31 | +{{- end -}} |
| 32 | + |
19 | 33 | <div class="hx:flex hx:justify-items-start {{ if $grow }}hx:grow{{ end }}"> |
20 | 34 | <button |
21 | 35 | title="{{ $changeLanguage }}" |
|
36 | 50 | style="position: fixed; inset: auto auto 0px 0px; margin: 0px; min-width: 100px;" |
37 | 51 | > |
38 | 52 | {{ range $versions }} |
39 | | - {{ $link := "/" }} |
| 53 | + {{ $targetVersion := . }} |
| 54 | + {{ $isLatest := eq $targetVersion $lastVersion }} |
| 55 | + {{ $base := cond $isLatest "/latest" (printf "/versions/v%s" $targetVersion) }} |
| 56 | + {{ $href := $base }} |
| 57 | + {{ with site.GetPage (path.Join $base $relPath) }} |
| 58 | + {{ $href = .RelPermalink }} |
| 59 | + {{ end }} |
40 | 60 | <li class="hx:flex hx:flex-col"> |
41 | 61 | <a |
42 | | - {{ if eq . $lastVersion }} |
43 | | - href="/" |
44 | | - {{ else }} |
45 | | - href="/versions/v{{ . }}" |
46 | | - {{ end }} |
| 62 | + href="{{ $href }}" |
47 | 63 | class="hx:text-gray-800 hx:dark:text-gray-100 hx:hover:bg-primary-50 hx:hover:text-primary-600 hx:hover:dark:bg-primary-500/10 hx:hover:dark:text-primary-600 hx:relative hx:cursor-pointer hx:whitespace-nowrap hx:py-1.5 hx:transition-colors hx:ltr:pl-3 hx:ltr:pr-9 hx:rtl:pr-3 hx:rtl:pl-9" |
48 | 64 | > |
49 | 65 | {{- . -}} |
|
0 commit comments