From db7a6f41ae57dff876006cc9dac03d64d3432ff6 Mon Sep 17 00:00:00 2001 From: George Cushen Date: Sat, 12 Oct 2019 22:18:22 +0100 Subject: [PATCH] feat(docs): add flexibility for using docs menu with `updates` layout --- layouts/_default/baseof.html | 13 +++++++------ layouts/partials/docs_layout.html | 8 ++++---- layouts/partials/docs_sidebar.html | 15 +++++++++++++-- layouts/partials/site_footer.html | 2 +- 4 files changed, 25 insertions(+), 13 deletions(-) diff --git a/layouts/_default/baseof.html b/layouts/_default/baseof.html index bd2cc532..ba50dc71 100644 --- a/layouts/_default/baseof.html +++ b/layouts/_default/baseof.html @@ -1,24 +1,25 @@ -{{ partial "site_head.html" . }} +{{ partial "site_head" . }} {{ partial "search" . }} - {{ partial "navbar.html" . }} + {{ partial "navbar" . }} {{ block "main" . }}{{ end }} - {{ partial "site_js.html" . }} + {{ partial "site_js" . }} - {{ if ne .Type "docs" }} + {{/* Docs and Updates layouts include the site footer in a different location. */}} + {{ if not (in (slice "docs" "updates") .Type) }}
- {{ partial "site_footer.html" . }} + {{ partial "site_footer" . }}
{{ end }} - {{ partial "citation.html" . }} + {{ partial "citation" . }} diff --git a/layouts/partials/docs_layout.html b/layouts/partials/docs_layout.html index 92c4e7c3..bc80575d 100644 --- a/layouts/partials/docs_layout.html +++ b/layouts/partials/docs_layout.html @@ -3,7 +3,7 @@
- {{ partial "docs_sidebar.html" . }} + {{ partial "docs_sidebar" . }}
{{ if .Params.toc }} @@ -14,7 +14,7 @@ {{ .TableOfContents }} - {{ partial "docs_toc_foot.html" . }} + {{ partial "docs_toc_foot" . }}
{{ end }} @@ -33,7 +33,7 @@ {{ if site.Params.docs_section_pager }}
- {{ partial "section_pager.html" . }} + {{ partial "section_pager" . }}
{{ end }}
@@ -48,7 +48,7 @@ - {{ partial "site_footer.html" . }} + {{ partial "site_footer" . }} diff --git a/layouts/partials/docs_sidebar.html b/layouts/partials/docs_sidebar.html index 4039603c..2cb9c329 100644 --- a/layouts/partials/docs_sidebar.html +++ b/layouts/partials/docs_sidebar.html @@ -1,7 +1,12 @@ {{ $current_page := . }} {{/* Dynamically load menu for this docs page. */}} -{{ $menu_name := path.Base (path.Split .CurrentSection.File).Dir }} +{{/* 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 }} +{{ end }} +{{ $menu_name = .Params.menu_name | default $menu_name | default (path.Base (path.Split .File).Dir) }} {{ if not (index site.Menus $menu_name) }} {{ errorf "Please define menu items named `menu: %s:` in your %s front matter or define `[[menu.%s]]` in `config/default/menus.toml`. See https://sourcethemes.com/academic/docs/managing-content/#menus" $menu_name .Path $menu_name }} {{ end }} @@ -18,7 +23,13 @@