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

Add git repo as a top-level menu #347

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
5 changes: 4 additions & 1 deletion site/hugo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,12 @@ imaging:

menu:
main:
- name: GitHub
url: https://github.com/apache/polaris

- name: "Docs & Releases"
identifier: "releases"
weight: 800
weight: 100
Copy link
Contributor Author

@flyrain flyrain Oct 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make "docs & releases" the first menu item.

params:
orderby: weight.desc
- name: "All Releases"
Expand Down
190 changes: 96 additions & 94 deletions site/layouts/partials/navbar.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,100 +23,102 @@
{{ $baseURL := urls.Parse $.Site.Params.Baseurl -}}

<nav class="td-navbar js-navbar-scroll
{{- if $cover }} td-navbar-cover {{- end }}" data-bs-theme="dark">
<div class="container-fluid flex-column flex-md-row">
<a class="navbar-brand" href="{{ .Site.Home.RelPermalink }}">
{{- /**/ -}}
<span class="navbar-brand__logo navbar-logo">
{{- if ne .Site.Params.ui.navbar_logo false -}}
{{ with resources.Get "icons/logo.svg" -}}
{{ ( . | minify).Content | safeHTML -}}
{{ end -}}
{{ end -}}
</span>
{{- /**/ -}}
<span class="navbar-brand__name">
{{- /* .Site.Title */ -}}
</span>
{{- /**/ -}}
</a>
<div class="td-navbar-nav-scroll ms-md-auto" id="main_navbar">
<ul class="navbar-nav">
{{ $p := . -}}
{{ $s := .Site -}}
{{ range .Site.Menus.main -}}
{{ if .HasChildren }}
{{/*
Customized to have drop-down menus in the navbar and 'Releases' not at the very right
*/}}
<div class="dropdown">
<a class="nav-link dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
{{- .Pre -}}
<span>{{ .Name }}</span>
</a>
<ul class="dropdown-menu">
{{ $children := .Children.ByWeight -}}
{{ if eq .Identifier "releases" -}}
{{ with (partial "releasePages.html" (dict "site" $s)).active -}}
{{ range . -}}
<a class="dropdown-item" href="{{ .RelPermalink }}">{{ .Params.LinkTitle | default .Params.Title }}</a>
{{- end -}}
{{ else -}}
{{ $children = where .Children.ByWeight "Identifier" "ne" "all-releases-page" -}}
{{ end -}}
{{ end -}}
{{ range $children -}}
<a class="dropdown-item" href="{{ .URL }}">{{ .Name }}</a>
{{- end -}}
</ul>
</div>
{{ else -}}
{{/*
Customized to allow hiding items from the navbar
*/}}
{{ if ne .Page.Params.top_hidden true -}}
<li class="nav-item">
{{ $active := or ($p.IsMenuCurrent "main" .) ($p.HasMenuCurrent "main" .) -}}
{{ $href := "" -}}
{{ with .Page -}}
{{ $active = or $active ( $.IsDescendant .) -}}
{{ $href = .RelPermalink -}}
{{ else -}}
{{ $href = .URL | relLangURL -}}
{{ end -}}
{{ $isExternal := ne $baseURL.Host (urls.Parse .URL).Host -}}
<a {{/**/ -}}
class="nav-link {{- if $active }} active {{- end }}" {{/**/ -}}
href="{{ $href }}"
{{- if $isExternal }} target="_blank" rel="noopener" {{- end -}}
>
{{- .Pre -}}
{{ if $cover }} td-navbar-cover {{ end }}" data-bs-theme="dark">
<div class="container-fluid flex-column flex-md-row">
<a class="navbar-brand" href="{{ .Site.Home.RelPermalink }}">
<span class="navbar-brand__logo navbar-logo">
{{ if ne .Site.Params.ui.navbar_logo false }}
{{ with resources.Get "icons/logo.svg" }}
{{ (. | minify).Content | safeHTML }}
{{ end }}
{{ end }}
</span>
</a>
<div class="td-navbar-nav-scroll ms-md-auto" id="main_navbar">
<ul class="navbar-nav">
{{ $p := . }}
{{ $s := .Site }}
{{ range .Site.Menus.main }}
{{ if .HasChildren }}
<!-- Menu items with children -->
<div class="dropdown">
<a class="nav-link dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
{{ .Pre }}
<span>{{ .Name }}</span>
{{- .Post -}}
</a>
</li>
{{ end -}}
{{ end -}}
{{ end -}}
{{ if .Site.Params.versions -}}
<li class="nav-item dropdown d-none d-lg-block">
{{ partial "navbar-version-selector.html" . -}}
</li>
{{ end -}}
{{ if (gt (len .Site.Home.Translations) 0) -}}
<li class="nav-item dropdown d-none d-lg-block">
{{ partial "navbar-lang-selector.html" . -}}
</li>
{{ end -}}
{{ if .Site.Params.ui.showLightDarkModeMenu -}}
<li class="td-light-dark-menu nav-item dropdown">
{{ partial "theme-toggler" . }}
</li>
{{ end -}}
</ul>
</div>
<div class="d-none d-lg-block">
{{ partial "search-input.html" . }}
</a>
<ul class="dropdown-menu">
{{ $children := .Children.ByWeight }}
{{ if eq .Identifier "releases" }}
{{ with (partial "releasePages.html" (dict "site" $s)).active }}
{{ range . }}
<a class="dropdown-item" href="{{ .RelPermalink }}">{{ .Params.LinkTitle | default .Params.Title }}</a>
{{ end }}
{{ else }}
{{ $children = where .Children.ByWeight "Identifier" "ne" "all-releases-page" }}
{{ end }}
{{ end }}
{{ range $children }}
<a class="dropdown-item" href="{{ .URL }}">{{ .Name }}</a>
{{ end }}
</ul>
</div>
{{ else }}
<!-- Menu items without children -->
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add the logic for menu items without children. Other changes in this PR are mainly formatting.

{{ $topHidden := false }}
{{ if .Page }}
{{ $topHidden = .Page.Params.top_hidden | default false }}
{{ else }}
{{ $topHidden = .Params.top_hidden | default false }}
{{ end }}
{{ if not $topHidden }}
<li class="nav-item">
{{ $active := or ($p.IsMenuCurrent "main" .) ($p.HasMenuCurrent "main" .) }}
{{ $href := "" }}
{{ with .Page }}
{{ $active = or $active ($p.IsDescendant .) }}
{{ $href = .RelPermalink }}
{{ else }}
{{ $href = .URL | relLangURL }}
{{ end }}
{{ $siteURL := urls.Parse $s.BaseURL }}
{{ $linkURL := urls.Parse $href }}
{{ $isExternal := false }}
{{ if and $siteURL $linkURL }}
{{ $isExternal = ne $siteURL.Host $linkURL.Host }}
{{ end }}
<a
class="nav-link{{ if $active }} active{{ end }}"
href="{{ $href }}"
{{ if $isExternal }} target="_blank" rel="noopener"{{ end }}
>
{{ .Pre }}
<span>{{ .Name }}</span>
{{ .Post }}
</a>
</li>
{{ end }}
{{ end }}
{{ end }}
<!-- Other navbar items -->
{{ if .Site.Params.versions }}
<li class="nav-item dropdown d-none d-lg-block">
{{ partial "navbar-version-selector.html" . }}
</li>
{{ end }}
{{ if gt (len .Site.Home.Translations) 0 }}
<li class="nav-item dropdown d-none d-lg-block">
{{ partial "navbar-lang-selector.html" . }}
</li>
{{ end }}
{{ if .Site.Params.ui.showLightDarkModeMenu }}
<li class="td-light-dark-menu nav-item dropdown">
{{ partial "theme-toggler" . }}
</li>
{{ end }}
</ul>
</div>
<div class="d-none d-lg-block">
{{ partial "search-input.html" . }}
</div>
</div>
</div>
</nav>