瀏覽代碼

Support multiple instances of docs layout with their own menus

Close #682
George Cushen 6 年之前
父節點
當前提交
304211dba0

+ 1 - 1
exampleSite/content/tutorial/_index.md

@@ -9,7 +9,7 @@ toc = true  # Show table of contents? true/false
 type = "docs"  # Do not modify.
 
 # Add menu entry to sidebar.
-[menu.docs]
+[menu.tutorial]
   name = "Overview"
   weight = 1
 

+ 1 - 1
exampleSite/content/tutorial/example.md

@@ -10,7 +10,7 @@ type = "docs"  # Do not modify.
 
 # Add menu entry to sidebar.
 linktitle = "Example Page"
-[menu.docs]
+[menu.tutorial]
   parent = "Example Topic"
   weight = 1
 

+ 11 - 4
layouts/partials/docs_sidebar.html

@@ -1,4 +1,9 @@
 {{ $current_page := . }}
+{{ $menu_name := .Section }}
+{{ with (index .Site.Menus $menu_name) }}
+{{ else }}
+{{ errorf "Please define menu items named `[menu.%s]` in your %s front matter or in `config.toml`." $menu_name $menu_name }}
+{{ end }}
 
 {{ if eq $.Site.Params.search.engine 1 }}
 <form class="docs-search d-flex align-items-center">
@@ -7,20 +12,22 @@
 {{ end }}
 
 <nav class="docs-links" id="docs-nav">
-  {{ range .Site.Menus.docs.ByWeight }}
-  <div class="docs-toc-item{{ if $current_page.IsMenuCurrent "docs" . }} active{{ end }}">
+  {{ with (index .Site.Menus $menu_name) }}
+  {{ range (index $.Site.Menus $menu_name).ByWeight }}
+  <div class="docs-toc-item{{ if $current_page.IsMenuCurrent $menu_name . }} active{{ end }}">
     <a class="docs-toc-link" {{ if .URL }}href="{{ .URL }}"{{else if .HasChildren }}href="{{ (index .Children 0).URL }}"{{end}}>{{ .Name }}</a>
 
     {{- if .HasChildren }}
     <ul class="nav docs-sidenav">
       {{ range .Children }}
-      <li {{ if $current_page.IsMenuCurrent "docs" . }}class="active"{{ end }}>
+      <li {{ if $current_page.IsMenuCurrent $menu_name . }}class="active"{{ end }}>
         <a href="{{ .URL }}">{{ .Name }}</a>
       </li>
       {{ end }}
     </ul>
-  {{ end }}
+    {{ end }}
 
   </div>
   {{ end }}
+  {{ end }}
 </nav>

+ 2 - 0
layouts/partials/footer_section.html

@@ -12,6 +12,7 @@
     <a href="https://sourcethemes.com/academic/" target="_blank" rel="noopener">Academic theme</a> for
     <a href="https://gohugo.io" target="_blank" rel="noopener">Hugo</a>.
 
+    {{ if ne .Type "docs" }}
     <span class="float-right" aria-hidden="true">
       <a href="#" id="back_to_top">
         <span class="button_icon">
@@ -19,5 +20,6 @@
         </span>
       </a>
     </span>
+    {{ end }}
   </p>
 </footer>