Improve hugo menu handling, add active class to current menu entity, name now takes over page title
This commit is contained in:
@@ -1,7 +1,6 @@
|
|||||||
---
|
---
|
||||||
menu:
|
menu:
|
||||||
after:
|
after:
|
||||||
name: blog
|
|
||||||
weight: 5
|
weight: 5
|
||||||
title: Blog
|
title: Blog
|
||||||
---
|
---
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
---
|
||||||
|
title: Showcases
|
||||||
|
layout: landing
|
||||||
|
---
|
||||||
|
|
||||||
|
<div class="book-hero text-center">
|
||||||
|
|
||||||
|
# At the moment this page is empty
|
||||||
|
|
||||||
|
<div>
|
||||||
@@ -42,24 +42,23 @@ enableGitInfo = true
|
|||||||
[menu]
|
[menu]
|
||||||
[[menu.home]]
|
[[menu.home]]
|
||||||
name = "Documentation"
|
name = "Documentation"
|
||||||
url = "/docs/example/"
|
pageRef = "/docs/example/"
|
||||||
weight = 1
|
weight = 1
|
||||||
|
|
||||||
[[menu.home]]
|
[[menu.home]]
|
||||||
name = "Introduction"
|
pageRef = "/docs/example/"
|
||||||
url = "/docs/example/"
|
|
||||||
weight = 10
|
weight = 10
|
||||||
parent = "Documentation"
|
parent = "Documentation"
|
||||||
|
|
||||||
[[menu.home]]
|
[[menu.home]]
|
||||||
name = "Shortcodes"
|
name = "Shortcodes"
|
||||||
url = "/docs/shortcodes/badges/"
|
pageRef = "/docs/shortcodes/badges/"
|
||||||
weight = 20
|
weight = 20
|
||||||
parent = "Documentation"
|
parent = "Documentation"
|
||||||
|
|
||||||
[[menu.home]]
|
[[menu.home]]
|
||||||
name = "Showcases"
|
name = "Showcases"
|
||||||
url = "/showcases/"
|
pageRef = "/showcases/"
|
||||||
weight = 2
|
weight = 2
|
||||||
|
|
||||||
[[menu.home]]
|
[[menu.home]]
|
||||||
|
|||||||
@@ -40,18 +40,17 @@ languages:
|
|||||||
menu:
|
menu:
|
||||||
home:
|
home:
|
||||||
- name: "Documentation"
|
- name: "Documentation"
|
||||||
url: "/docs/example/"
|
pageRef: "/docs/example/"
|
||||||
weight: 1
|
weight: 1
|
||||||
- name: "Introduction"
|
- pageRef: "/docs/example/"
|
||||||
url: "/docs/example/"
|
|
||||||
weight: 10
|
weight: 10
|
||||||
parent: "Documentation"
|
parent: "Documentation"
|
||||||
- name: "Shortcodes"
|
- name: "Shortcodes"
|
||||||
url: "/docs/shortcodes/badges/"
|
pageRef: "/docs/shortcodes/badges/"
|
||||||
weight: 20
|
weight: 20
|
||||||
parent: "Documentation"
|
parent: "Documentation"
|
||||||
- name: "Showcases"
|
- name: "Showcases"
|
||||||
url: "/showcases/"
|
pageRef: "/showcases/"
|
||||||
weight: 2
|
weight: 2
|
||||||
- name: "Github"
|
- name: "Github"
|
||||||
url: "https://github.com/alex-shpak/hugo-book/"
|
url: "https://github.com/alex-shpak/hugo-book/"
|
||||||
|
|||||||
@@ -1,29 +1,43 @@
|
|||||||
<!--
|
<!--
|
||||||
This is template for hugo menus, accepts MenuEntity as context
|
This is template for hugo menus, accepts Page and Menu as context
|
||||||
https://gohugo.io/variables/menus/
|
https://gohugo.io/variables/menus/
|
||||||
-->
|
-->
|
||||||
{{ if . }}
|
{{- if .Menu -}}
|
||||||
{{ template "book-menu-hugo" . }}
|
{{- template "book-menu-hugo" . -}}
|
||||||
{{ end }}
|
{{- end -}}
|
||||||
|
|
||||||
{{ define "book-menu-hugo" }}
|
{{ define "book-menu-hugo" }}
|
||||||
<ul>
|
<ul>
|
||||||
{{ range . }}
|
{{- range .Menu -}}
|
||||||
|
{{- $class := slice -}}
|
||||||
|
{{- with .Params.class -}}
|
||||||
|
{{- $class = $class | append . -}}
|
||||||
|
{{- end -}}
|
||||||
|
{{- if $.Page.IsMenuCurrent .Menu . -}}
|
||||||
|
{{- $class = $class | append "active" -}}
|
||||||
|
{{- end -}}
|
||||||
<li>
|
<li>
|
||||||
{{ $isRemote := not (or (.Page) (strings.HasPrefix .URL "/")) }}
|
{{- $isRemote := not (or (.Page) (strings.HasPrefix .URL "/")) -}}
|
||||||
<a href="{{ .URL }}" {{ with .Params.class }}class="{{ . }}"{{ end }} {{ if $isRemote }}target="_blank" rel="noopener"{{ end }}>
|
<a href="{{ .URL }}"
|
||||||
|
{{- with $class }}class="{{ delimit . " " }}"{{ end -}}
|
||||||
|
{{- with .Title }}title="{{ . }}"{{ end -}}
|
||||||
|
{{- if $isRemote }}target="_blank" rel="noopener"{{ end -}}>
|
||||||
{{- .Pre -}}
|
{{- .Pre -}}
|
||||||
{{ with .Page }}
|
{{ template "book-menu-title" . }}
|
||||||
{{ partial "docs/title" .Page }}
|
|
||||||
{{ else }}
|
|
||||||
{{ .Name }}
|
|
||||||
{{ end }}
|
|
||||||
{{- .Post -}}
|
{{- .Post -}}
|
||||||
</a>
|
</a>
|
||||||
{{- with .Children }}
|
{{- with .Children }}
|
||||||
{{ template "book-menu-hugo" . }}
|
{{ template "book-menu-hugo" (dict "Page" $.Page "Menu" .) }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
</li>
|
</li>
|
||||||
{{ end }}
|
{{- end -}}
|
||||||
</ul>
|
</ul>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
||||||
|
{{ define "book-menu-title" }}
|
||||||
|
{{ if .Name }}
|
||||||
|
{{ .Name }}
|
||||||
|
{{ else if .Page }}
|
||||||
|
{{ partial "docs/title" .Page }}
|
||||||
|
{{ end }}
|
||||||
|
{{ end }}
|
||||||
@@ -6,11 +6,11 @@
|
|||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
||||||
{{ partial "docs/inject/menu-before" . }}
|
{{ partial "docs/inject/menu-before" . }}
|
||||||
{{ partial "docs/menu-hugo" .Site.Menus.before }}
|
{{ partial "docs/menu-hugo" (dict "Page" .Page "Menu" .Site.Menus.before) }}
|
||||||
|
|
||||||
{{ partial "docs/menu-filetree" . }}
|
{{ partial "docs/menu-filetree" . }}
|
||||||
|
|
||||||
{{ partial "docs/menu-hugo" .Site.Menus.after }}
|
{{ partial "docs/menu-hugo" (dict "Page" .Page "Menu" .Site.Menus.after) }}
|
||||||
{{ partial "docs/inject/menu-after" . }}
|
{{ partial "docs/inject/menu-after" . }}
|
||||||
</nav>
|
</nav>
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,6 @@
|
|||||||
|
|
||||||
{{ define "header" }}
|
{{ define "header" }}
|
||||||
<nav>
|
<nav>
|
||||||
{{ partial "docs/menu-hugo" .Site.Menus.home }}
|
{{ partial "docs/menu-hugo" (dict "Page" .Page "Menu" .Site.Menus.home) }}
|
||||||
</nav>
|
</nav>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|||||||
Reference in New Issue
Block a user