refactor: docs menu name detection logic

Enables streamlining Academic docs front matter with just `menu: "updates"` for example.
This commit is contained in:
George Cushen committed 2020-01-24 00:57:50 +00:00
1 parent 7c87076824
commit c74f07dd01
1 file changed
+6 -2
+6 -2
View File
@@ -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) }}