Skip to content

Commit 2af8c3a

Browse files
Highlight tutorials in top navigation bar across all tutorial subpages
1 parent d9a35f6 commit 2af8c3a

3 files changed

Lines changed: 15 additions & 5 deletions

File tree

‎data/topnav.yml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ topnav:
55
- title: Topnav
66
items:
77
- title: Quickstart
8-
url: /quickstart.html
8+
url: /tutorials/quickstart/
99
section:
1010
- title: Docs
1111
url: /docs/fundamentals/overview/
1212
section: docs
1313
- title: Tutorials
1414
url: /tutorials/overview/
15-
section: tutorial
15+
section: tutorials
1616
- title: Community
1717
url: /community/overview/
1818
section: community

‎layouts/partials/breadcrumb.html‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
{{- range $entry := $topnav.topnav -}}
66
{{- range $item := $entry.items -}}
77
{{- $sectionSidebar := printf "%s_sidebar" ($item.section | default "") -}}
8-
{{- if or (and $item.url (in $.RelPermalink $item.url)) (eq ($.Param "sidebar") $sectionSidebar) -}}
8+
{{- if or (and $item.url (in $.RelPermalink $item.url)) (eq ($.Param "sidebar") $sectionSidebar) (and $item.section (eq $.Section $item.section)) -}}
99
{{- $sectionTitle = $item.title -}}
1010
{{- $sectionURL = $item.url -}}
1111
{{- end -}}

‎layouts/partials/topnav.html‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,25 @@
1616
</div>
1717
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
1818
<ul class="nav navbar-nav ms-auto">
19+
{{- $hasExactMatch := false -}}
20+
{{- range $entry := $topnav.topnav -}}
21+
{{- range $item := $entry.items -}}
22+
{{- with $item.url -}}
23+
{{- if partial "sidebar_page_matches_url.html" (dict "page" $page "url" .) -}}
24+
{{- $hasExactMatch = true -}}
25+
{{- end -}}
26+
{{- end -}}
27+
{{- end -}}
28+
{{- end -}}
1929
{{ range $entry := $topnav.topnav }}
2030
{{ range $item := $entry.items }}
2131
{{ $sectionSidebar := printf "%s_sidebar" ($item.section | default "") }}
2232
{{ $isActive := false }}
2333
{{ with $item.url }}
2434
{{ $isActive = partial "sidebar_page_matches_url.html" (dict "page" $page "url" .) }}
2535
{{ end }}
26-
{{ if and (not $isActive) $item.section }}
27-
{{ $isActive = eq ($page.Param "sidebar") $sectionSidebar }}
36+
{{ if and (not $hasExactMatch) (not $isActive) $item.section }}
37+
{{ $isActive = or (eq ($page.Param "sidebar") $sectionSidebar) (eq $page.Section $item.section) }}
2838
{{ end }}
2939
<li class="nav-item{{ if $isActive }} active{{ end }}">
3040
{{ if $item.external_url }}

0 commit comments

Comments
 (0)