Skip to content
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
44 changes: 44 additions & 0 deletions docsy.dev/content/en/docs/content/navigation.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,50 @@ Navbar entries are ordered from left to right by `weight`. So, for example, a
section index or page with `weight: 30` would appear after the Documentation
section in the menu, while one with `weight: 10` would appear before it.

To group menu items in a dropdown, add a `parent` parameter to the page front
matter. All menu items with the same `parent` value will be grouped together
under a dropdown menu. For example, here's how to add a page to a
"Community" dropdown:

{{< tabpane >}}
{{< tab header="Front matter:" disabled=true />}}
{{< tab header="toml" lang="toml" >}}
+++
title = "Contributing to the Project"
linkTitle = "Contributing"
description = "How to contribute to our documentation project."

[menu.main]
parent = "Community"
weight = 10
+++
{{< /tab >}}
{{< tab header="yaml" lang="yaml" >}}
---
title: "Contributing to the Project"
linkTitle: "Contributing"
description: "How to contribute to our documentation project."
menu:
main:
parent: "Community"
weight: 10
---
{{< /tab >}}
{{< tab header="json" lang="json" >}}
{
"title": "Contributing to the Project",
"linkTitle": "Contributing",
"description": "How to contribute to our documentation project.",
"menu": {
"main": {
"parent": "Community",
"weight": 10
}
}
}
{{< /tab >}}
{{< /tabpane >}}

If you want to add a link to an external site to this menu, add it to your site
configuration:[^add-external-link-via]

Expand Down
13 changes: 13 additions & 0 deletions layouts/_partials/navbar-general-selector.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<a class="nav-link {{- if .active }} active {{- end }} dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
{{ .menuItem.Name }}
</a>
<ul class="dropdown-menu">
{{ $page := .page -}}
{{ range .menuItem.Children -}}
{{ $isActive := or ($page.IsMenuCurrent "main" .) ($page.HasMenuCurrent "main" .) -}}
{{ with .Page -}}
{{ $isActive = or $isActive ( $page.IsDescendant .) -}}
{{ end -}}
<li><a class="dropdown-item {{- if $isActive }} active {{- end }}" href="{{ .URL }}">{{ .Name }}</a></li>
{{ end -}}
</ul>
24 changes: 15 additions & 9 deletions layouts/_partials/navbar.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,20 @@
<ul class="navbar-nav">
{{ $p := . -}}
{{ range .Site.Menus.main -}}
{{ $active := or ($p.IsMenuCurrent "main" .) ($p.HasMenuCurrent "main" .) -}}
{{ $href := "" -}}
{{ with .Page -}}
{{ $active = or $active ( $.IsDescendant .) -}}
{{ $href = .RelPermalink -}}
{{ else -}}
{{ $href = .URL | relLangURL -}}
{{ end -}}
{{ if .HasChildren -}}
<li class="nav-item">
{{ partial "navbar-general-selector.html" (dict "menuItem" . "active" $active "page" $p) -}}
</li>
{{ else -}}
<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 }}" {{/**/ -}}
Expand All @@ -48,6 +53,7 @@
</a>
</li>
{{ end -}}
{{ end -}}
{{ if .Site.Params.versions -}}
<li class="nav-item dropdown d-none d-lg-block td-navbar__version-menu">
{{ partial "navbar-version-selector.html" . -}}
Expand All @@ -71,4 +77,4 @@
{{ partial "search-input.html" . }}
</div>
</div>
</nav>
</nav>