refactor(menu): use .Params.icon to configure menu item icon

Using [pre] field will result a warning, but will keeping working for compatibility
This commit is contained in:
Jimmy Cai 2021-10-23 06:59:22 +00:00 committed by GitHub
parent a822411a03
commit b6e4f0e489
5 changed files with 12 additions and 5 deletions

View File

@ -174,10 +174,10 @@ menu:
name: Home
url: /
weight: -100
pre: home
params:
### For demonstration purpose, the home link will be open in a new tab
newTab: true
icon: home
related:
includeNewer: true

View File

@ -11,7 +11,8 @@ lastmod: '2020-10-09'
menu:
main:
weight: -90
pre: user
params:
icon: user
---
Written in Go, Hugo is an open source static site generator available under the [Apache Licence 2.0.](https://github.com/gohugoio/hugo/blob/master/LICENSE) Hugo supports TOML, YAML and JSON data file types, Markdown and HTML content files and uses shortcodes to add rich content. Other notable features are taxonomies, multilingual mode, image processing, custom output formats, HTML/CSS/JS minification and support for Sass SCSS workflows.

View File

@ -6,5 +6,6 @@ slug: "archives"
menu:
main:
weight: -70
pre: archives
params:
icon: archives
---

View File

@ -8,5 +8,6 @@ outputs:
menu:
main:
weight: -60
pre: search
params:
icon: search
---

View File

@ -40,8 +40,12 @@
<li {{ if $active }} class='current' {{ end }}>
<a href='{{ .URL | relLangURL }}' {{ if eq .Params.newTab true }}target="_blank"{{ end }}>
{{ $icon := default .Pre .Params.Icon }}
{{ if .Pre }}
{{ partial "helper/icon" .Pre }}
{{ warnf "Menu item [%s] is using [pre] field to set icon, please use [params.icon] instead" .URL }}
{{ end }}
{{ with $icon }}
{{ partial "helper/icon" . }}
{{ end }}
<span>{{- .Name -}}</span>
</a>