Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: improve display of releases in navbar #906

Merged
merged 9 commits into from
Dec 8, 2021
3 changes: 1 addition & 2 deletions website/assets/scss/_variables_project.scss
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,4 @@ nav.navbar-dark {
code.provisioner {
color: $light;
}
}

}
10 changes: 3 additions & 7 deletions website/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ images = ["banner.png"]
# Menu title if your navbar has a versions selector to access old versions of your site.
# This menu appears only if you have at least one [params.versions] set.
version_menu = "Releases"

# Flag used in the "version-banner" partial to decide whether to display a
# banner on every page indicating that this is an archived version of the docs.
# Set this flag to "true" if you want to display the banner.
Expand Down Expand Up @@ -134,15 +135,10 @@ url = "https://github.com/aws/karpenter"
pre = "<i class='fab fa-github'></i>"

# Add your release versions here
[[params.versions]]
version = "latest"
url = "https://karpenter.sh/docs/"

[[params.versions]]
version = "v0.5.0"
url = "https://karpenter.sh/docs/"
url = "/docs/"

[[params.versions]]
version = "v0.4.3"
url = "https://karpenter.sh/v0.4.3-docs/"

url = "/v0.4.3-docs/"
19 changes: 19 additions & 0 deletions website/layouts/partials/navbar-version-selector.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{{ $pageDir := index (split (path.Dir .Page.RelPermalink) "/") 1 }}
<!-- special treatment for the homepage. we treat it same as latest docs //-->
{{ if eq $pageDir "" }}
{{ $pageDir = "docs" }}
{{ end }}
{{ $currentDocVer := $pageDir }}
{{ range .Site.Params.versions }}
{{ if eq .url (printf "/%s/" $pageDir) }}
{{ $currentDocVer = .version }}
{{ end }}
{{ end }}
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
{{ $currentDocVer }}
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink" id="navbarVersionSelector">
{{ range .Site.Params.versions }}
<a class="dropdown-item" href="{{ .url }}">{{ .version }}</a>
{{ end }}
</div>
38 changes: 38 additions & 0 deletions website/layouts/partials/navbar.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{{ $cover := .HasShortcode "blocks/cover" }}
<nav class="js-navbar-scroll navbar navbar-expand-md navbar-dark {{ if $cover}} td-navbar-cover {{ end }} td-navbar py-2">
<a class="navbar-brand" href="{{ .Site.Home.RelPermalink }}">
<span class="navbar-logo">{{ if .Site.Params.ui.navbar_logo }}{{ with resources.Get "icons/logo.svg" }}{{ ( . | minify).Content | safeHTML }}{{ end }}{{ end }}</span><span class="text-uppercase font-weight-bold">{{ .Site.Title }}</span>
</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#main_navbar" aria-controls="main_navbar" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse ml-md-auto" id="main_navbar">
<ul class="navbar-nav ml-auto pt-4 pt-md-0 my-2 my-md-1">
{{ $p := . }}
{{ range .Site.Menus.main }}
<li class="nav-item mr-2 mr-lg-4 mt-1 mt-lg-0">
{{ $active := or ($p.IsMenuCurrent "main" .) ($p.HasMenuCurrent "main" .) }}
{{ with .Page }}
{{ $active = or $active ( $.IsDescendant .) }}
{{ end }}
{{ $pre := .Pre }}
{{ $post := .Post }}
{{ $url := urls.Parse .URL }}
{{ $baseurl := urls.Parse $.Site.Params.Baseurl }}
<a class="nav-link{{if $active }} active{{end}}" href="{{ with .Page }}{{ .RelPermalink }}{{ else }}{{ .URL | relLangURL }}{{ end }}" {{ if ne $url.Host $baseurl.Host }}target="_blank" {{ end }}>{{ with .Pre}}{{ $pre }}{{ end }}<span{{if $active }} class="active"{{end}}>{{ .Name }}</span>{{ with .Post}}{{ $post }}{{ end }}</a>
</li>
{{ end }}
{{ if .Site.Params.versions }}
<li class="nav-item dropdown mt-1 mt-lg-0 mr-2">
{{ partial "navbar-version-selector.html" . }}
</li>
{{ end }}
{{ if (gt (len .Site.Home.Translations) 0) }}
<li class="nav-item dropdown mt-1 mt-lg-0">
{{ partial "navbar-lang-selector.html" . }}
</li>
{{ end }}
</ul>
</div>
<div class="navbar-nav d-none d-lg-block">{{ partial "search-input.html" . }}</div>
</nav>