Browse Source

refactor: docs menu name detection logic

Enables streamlining Academic docs front matter with just `menu: "updates"` for example.
George Cushen 5 years ago
parent
commit
c74f07dd01
1 changed files with 6 additions and 2 deletions
  1. 6 2
      layouts/partials/docs_sidebar.html

+ 6 - 2
layouts/partials/docs_sidebar.html

@@ -3,8 +3,12 @@
 {{/* Dynamically load menu for this docs page. */}}
 {{/* Attempt to get menu name from `menu_name` param, Hugo's front matter menu config, or the last dir of filepath. */}}
 {{ $menu_name := "" }}
-{{ range $k, $v := .Params.menu }}
-  {{ $menu_name = $k }}
+{{ if .Params.menu | and (not (reflect.IsMap .Params.menu)) | and (not (reflect.IsSlice .Params.menu)) }}
+  {{ $menu_name = .Params.menu }}
+{{ else if .Params.menu | and (or (reflect.IsMap .Params.menu) (reflect.IsSlice .Params.menu)) }}
+  {{ range $k, $v := .Params.menu }}
+    {{ $menu_name = $k }}
+  {{ end }}
 {{ end }}
 {{ $menu_name = .Params.menu_name | default $menu_name | default (path.Base (path.Split .File).Dir) }}
 {{ if not (index site.Menus $menu_name) }}