Browse Source

feat(shortcodes): add navmenu navigational aid

Josh Habdas 1 year ago
parent
commit
aa46ed30a4
Signed by: Josh Habdas <jhabdas@protonmail.com> GPG Key ID: B148B31154C75A74

+ 2
- 1
archetypes/help.md View File

@@ -492,7 +492,8 @@ Snippets are reusable bits of code you can add to your site to reduce repetition
492 492
 
493 493
 The following core snippets are supplied by the theme:
494 494
 
495
-- `external` - Create styled links in layout or markdown.
495
+- `external` - Create styled anchor links.
496
+- `navmenu` - Displays a navigation menu.
496 497
 
497 498
 After Dark also includes snippets to take advantage of [hackcss components][hackcss]:
498 499
 

+ 6
- 0
layouts/partials/components/navmenu.html View File

@@ -0,0 +1,6 @@
1
+<nav itemscope itemtype="http://schema.org/SiteNavigationElement">
2
+  {{ range (index .menus .name) }}
3
+    {{ $is_active := or ($.page.IsMenuCurrent $.name .) ($.page.HasMenuCurrent $.name .) }}
4
+    <a itemprop="url" {{ if $is_active }}class="active"{{ end }} href="{{ .URL }}"><span itemprop="name">{{ .Name }}</span></a>
5
+  {{- end }}
6
+</nav>

+ 1
- 6
layouts/partials/menu.html View File

@@ -1,8 +1,3 @@
1 1
 {{ if ne .Site.Params.show_menu false }}
2
-  <nav itemscope itemtype="http://schema.org/SiteNavigationElement">
3
-    {{ $currentNode := . }}
4
-    {{ range .Site.Menus.main }}
5
-      <a itemprop="url" class="{{if or ($currentNode.IsMenuCurrent "main" .) ($currentNode.HasMenuCurrent "main" .) }}active{{end}}" href="{{ .URL }}"><span itemprop="name">{{ .Name }}</span></a>
6
-    {{ end }}
7
-  </nav>
2
+  {{ partial "components/navmenu.html" (dict "name" "main" "menus" .Site.Menus "page" .)}}
8 3
 {{ end }}

+ 13
- 0
layouts/shortcodes/navmenu.html View File

@@ -0,0 +1,13 @@
1
+<!-- {{/*
2
+Attributes: name [default: "main"]
3
+
4
+Display main navigation menu:
5
+{{< navmenu >}}
6
+
7
+Display custom navigation menu:
8
+{{< navmenu "sidebar" >}}
9
+
10
+*/}} -->
11
+
12
+{{ $name := .Get 0 | default "main" }}
13
+{{ partial "components/navmenu.html" (dict "name" $name "menus" .Site.Menus "page" .Page.Page)}}

Loading…
Cancel
Save