Browse Source

feat(docs): add flexibility for using docs menu with `updates` layout

George Cushen 5 năm trước cách đây
mục cha
commit
db7a6f41ae

+ 7 - 6
layouts/_default/baseof.html

@@ -1,24 +1,25 @@
 <!DOCTYPE html>
 <html lang="{{ site.LanguageCode | default "en-us" }}">
 
-{{ partial "site_head.html" . }}
+{{ partial "site_head" . }}
 <body id="top" data-spy="scroll" data-offset="70" data-target="{{ if or .IsHome (eq .Type "widget_page") }}#navbar-main{{else}}#TableOfContents{{end}}" {{ if not (.Scratch.Get "light") }}class="dark"{{end}}>
 
   {{ 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) }}
   <div class="container">
-    {{ partial "site_footer.html" . }}
+    {{ partial "site_footer" . }}
   </div>
   {{ end }}
 
-  {{ partial "citation.html" . }}
+  {{ partial "citation" . }}
 
 </body>
 </html>

+ 4 - 4
layouts/partials/docs_layout.html

@@ -3,7 +3,7 @@
 <div class="container-fluid docs">
   <div class="row flex-xl-nowrap">
     <div class="col-12 col-md-3 col-xl-2 docs-sidebar">
-      {{ partial "docs_sidebar.html" . }}
+      {{ partial "docs_sidebar" . }}
     </div>
 
     {{ if .Params.toc }}
@@ -14,7 +14,7 @@
 
       {{ .TableOfContents }}
 
-      {{ partial "docs_toc_foot.html" . }}
+      {{ partial "docs_toc_foot" . }}
     </div>
     {{ end }}
 
@@ -33,7 +33,7 @@
 
           {{ if site.Params.docs_section_pager }}
           <div class="article-widget">
-            {{ partial "section_pager.html" . }}
+            {{ partial "section_pager" . }}
           </div>
           {{ end }}
         </div>
@@ -48,7 +48,7 @@
 
       </article>
 
-      {{ partial "site_footer.html" . }}
+      {{ partial "site_footer" . }}
 
     </main>
   </div>

+ 13 - 2
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 @@
 
 <nav class="collapse docs-links" id="docs-nav">
   {{ with (index site.Menus $menu_name) }}
-  {{ range (index site.Menus $menu_name).ByWeight }}
+
+  {{/* Enable Updates layout to order by descending version name. */}}
+  {{ $menu := (index site.Menus $menu_name).ByWeight }}
+  {{ if eq ($.Scratch.Get "docs_menu_sort" | default "weight") "name_reverse" }}
+    {{ $menu = (index site.Menus $menu_name).ByName.Reverse }}
+  {{end}}
+  {{ range $menu }}
   <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>
 

+ 1 - 1
layouts/partials/site_footer.html

@@ -18,7 +18,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" }}
+    {{ if not (in (slice "docs" "updates") .Type) }}
     <span class="float-right" aria-hidden="true">
       <a href="#" class="back-to-top">
         <span class="button_icon">