Skip to content

Commit

Permalink
Add support for v2 docs in the navigation (#765)
Browse files Browse the repository at this point in the history
## Which problem is this PR solving?
- Part of #731

## Description of the changes
- Add new V2 variables to config
- Change the display of the current / latest version on the doc pages to
allow switching between 1.x and 2.x
- Update Versions navbar dropdown to include 2.x versions (currently
disabled until we actually have 2.0)

## How was this change tested?
- Locally

---------

Signed-off-by: Yuri Shkuro <[email protected]>
  • Loading branch information
yurishkuro authored Nov 3, 2024
1 parent bb60377 commit c8d46c9
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 24 deletions.
6 changes: 5 additions & 1 deletion config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ home = [ "HTML", "JSON", "REDIRECTS" ]

latest = "1.62"
binariesLatest = "1.62.0"
versions = ["1.62","1.61","1.60","1.59","1.58","1.57","1.56","1.55","1.54","1.53","1.52","1.51","1.50","1.49","1.48","1.47","1.46","1.45","1.44","1.43","1.42","1.41","1.40","1.39","1.38","1.37","1.36","1.35","1.34","1.33","1.32"]
versions = ["1.62","1.61","1.60","1.59","1.58","1.57","1.56","1.55","1.54","1.53","1.52"]

latestV2 = "next-release-v2"
binariesLatestV2 = "2.0.0-rc2"
versionsV2 = []

[navbar]
[[links]]
Expand Down
50 changes: 38 additions & 12 deletions themes/jaeger-docs/layouts/partials/docs/header.html
Original file line number Diff line number Diff line change
@@ -1,15 +1,33 @@
{{ $versions := site.Params.versions }}
{{ $latest := site.Params.latest }}
{{ $path := "" }}
{{ $path := "" }}
{{ with .File }}
{{ $path = .Path }}
{{ else }}
{{ $path = .Path }}
{{ end }}
{{ $latestV1 := site.Params.latest }}
{{ $latestV2 := site.Params.latestV2 }}
{{ $version := index (split $path "/") 1 }}
{{ $isLatest := eq $version $latest }}
{{ $isNextRelease := eq $version "next-release" }}
{{ $latestUrl := .RelPermalink | replaceRE $version $latest }}
{{ $vMajor := index (split $version ".") 0 }}
{{ $isNextRelease := false }}
{{ if eq $version "next-release" }}
{{ $vMajor = "1" }}
{{ $isNextRelease = true }}
{{ else if eq $version "next-release-v2" }}
{{ $vMajor = "2" }}
{{ $isNextRelease = true }}
{{ end }}

{{ $isLatest := or (eq $version $latestV1) (eq $version $latestV2) }}
{{ $latestUrlV1 := .RelPermalink | replaceRE $version $latestV1 }}
{{ $latestUrlV2 := .RelPermalink | replaceRE $version $latestV2 }}

{{ $latestUrl := "" }}
{{ if eq $vMajor "1" }}
{{ $latestUrl = .RelPermalink | replaceRE $version $latestV1 }}
{{ else if eq $vMajor "2" }}
{{ $latestUrl = .RelPermalink | replaceRE $version $latestV2 }}
{{ end }}

<header>
<p class="title is-1">{{ .Title }}</p>
{{ with .Params.description }}
Expand All @@ -21,18 +39,26 @@
<span class="tag is-medium">
Version&nbsp;&nbsp;<strong>{{ $version }}</strong>
</span>
{{ if $isNextRelease }}
<span class="tag is-medium is-info">Preview</span>
{{ end }}
{{ if $isLatest }}
<span class="tag is-medium is-success">Latest</span>
{{ else if $isNextRelease }}
<a class="tag is-medium is-info">
Preview
</a>
{{ else }}
<a class="tag is-medium is-warning" href="{{ $latestUrl }}">
Click here for the latest version
Go to the latest {{ $vMajor }}.x version
</a>
{{ end }}
{{ if eq $vMajor "1" }}
<a class="tag is-medium" href="{{ $latestUrlV2 }}">
Go to the latest 2.x version
</a>
{{ else if eq $vMajor "2" }}
<a class="tag is-medium" href="{{ $latestUrlV1 }}">
Go to the latest 1.x version
</a>
{{ end }}
</div>
</div>
{{ end }}

<hr class="hr" />
Expand Down
34 changes: 23 additions & 11 deletions themes/jaeger-docs/layouts/partials/navbar.html
Original file line number Diff line number Diff line change
@@ -1,19 +1,28 @@
{{ $menuPages := site.Menus.docs }}
{{ $githubRepo := site.Params.githubrepo }}
{{ $twitterHandle := site.Params.twitterhandle }}
{{ $versions := site.Params.versions }}
{{ $latest := site.Params.latest }}
{{ $versionsV1 := site.Params.versions }}
{{ $versionsV2 := site.Params.versionsV2 }}
{{ $versions := append $versionsV1 $versionsV2 }}
{{ $latestV1 := site.Params.latest }}
{{ $latestV2 := site.Params.latestV2 }}
{{ $docs := where site.Pages "Section" "docs" }}
{{ $isDocsPage := eq .Section "docs" }}
{{ $preview := getenv "HUGO_PREVIEW" }}
{{ $isPreview := eq $preview "true" }}
{{ $isPreview := eq (getenv "HUGO_PREVIEW") "true" }}
{{ $path := "" }}
{{ with .File }}
{{ $path = .Path }}
{{ else }}
{{ $path = .Path }}
{{ end }}
{{ $majorMinorVersion := index (split $path "/") 1 }}
{{ $vMajor := index (split $majorMinorVersion ".") 0 }}
{{ if eq $majorMinorVersion "next-release" }}
{{ $vMajor = "1" }}
{{ else if eq $majorMinorVersion "next-release-v2" }}
{{ $vMajor = "2" }}
{{ end }}
{{ $isLatest := or (eq $majorMinorVersion $latestV1) (eq $majorMinorVersion $latestV2) }}
<nav class="navbar is-fixed-top">
<div class="container is-fluid">
<div class="navbar-brand">
Expand All @@ -31,8 +40,7 @@

<div id="topNav" class="navbar-menu">
<div class="navbar-end">
{{ if $isDocsPage }}
{{ if eq $latest $majorMinorVersion }}
{{ if and $isDocsPage $isLatest }}
<div class="navbar-item">
<div class="dropdown" id="search-dropdown">
<div class="dropdown-trigger">
Expand All @@ -53,7 +61,6 @@
</div>
</div>
{{ end }}
{{ end }}

<div class="navbar-item has-dropdown is-hoverable" id="sandwich-popup-menu">
<a class="navbar-link">
Expand All @@ -70,15 +77,17 @@
{{ $docVersion := index (split $docPath "/") 1 }}
<!-- When generating Docs menu for home page, use the latest version, -->
<!-- when generating menu for pages inside docs/, use same version as the doc -->
{{ $matchVersion := cond ($isDocsPage) $majorMinorVersion $latest }}
<!-- TODO: replace with $latestV2 once 2.0 is released -->
{{ $matchVersion := cond ($isDocsPage) $majorMinorVersion $latestV1 }}
{{ if and (eq $docVersion $matchVersion) (not .Params.hasparent) }}
<a class="navbar-item" href="{{ .RelPermalink }}">
{{ .Title }}
</a>

{{ with .Params.children }}
{{ range . }}
{{ $url := cond $isDocsPage (printf "/docs/%s/%s" $majorMinorVersion .url) (printf "/docs/%s/%s" $latest .url) }}
<!-- TODO: replace with $latestV2 once 2.0 is released -->
{{ $url := cond $isDocsPage (printf "/docs/%s/%s" $majorMinorVersion .url) (printf "/docs/%s/%s" $latestV1 .url) }}
<a class="navbar-item is-small is-hidden-desktop" href="{{ $url }}">
&cir; {{ if .navtitle }}{{ .navtitle }}{{ else }}{{ .title }}{{ end }}
</a>
Expand All @@ -97,14 +106,17 @@
<div class="navbar-dropdown">
{{ range $versions }}
{{ $version := . }}
{{ $isLatest := eq $version $latest }}
{{ $isLatest := or (eq $version $latestV1) (eq $version $latestV2) }}
<a class="navbar-item" href="/docs/{{ $version }}">
{{ $version }}{{ if $isLatest }}&nbsp;&nbsp;(<strong>latest</strong>){{ end }}
</a>
{{ end }}
{{ if $isPreview }}
<a class="navbar-item" href="/docs/next-release-v2">
next release 2.0&nbsp;&nbsp;(preview)
</a>
<a class="navbar-item" href="/docs/next-release">
next-release&nbsp;&nbsp;(preview)
next release 1.0&nbsp;&nbsp;(preview)
</a>
{{ end }}
</div>
Expand Down

0 comments on commit c8d46c9

Please sign in to comment.