Skip to content

Commit 7c59ac7

Browse files
authored
refactor(menu): use .Params.icon to configure menu item icon (#400)
1 parent a822411 commit 7c59ac7

File tree

5 files changed

+12
-5
lines changed

5 files changed

+12
-5
lines changed

exampleSite/config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,10 +174,10 @@ menu:
174174
name: Home
175175
url: /
176176
weight: -100
177-
pre: home
178177
params:
179178
### For demonstration purpose, the home link will be open in a new tab
180179
newTab: true
180+
icon: home
181181

182182
related:
183183
includeNewer: true

exampleSite/content/page/about.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ lastmod: '2020-10-09'
1111
menu:
1212
main:
1313
weight: -90
14-
pre: user
14+
params:
15+
icon: user
1516
---
1617

1718
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.

exampleSite/content/page/archives.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@ slug: "archives"
66
menu:
77
main:
88
weight: -70
9-
pre: archives
9+
params:
10+
icon: archives
1011
---

exampleSite/content/page/search.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@ outputs:
88
menu:
99
main:
1010
weight: -60
11-
pre: search
11+
params:
12+
icon: search
1213
---

layouts/partials/sidebar/left.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,12 @@ <h2 class="site-description">{{ .Site.Params.sidebar.subtitle }}</h2>
4040

4141
<li {{ if $active }} class='current' {{ end }}>
4242
<a href='{{ .URL | relLangURL }}' {{ if eq .Params.newTab true }}target="_blank"{{ end }}>
43+
{{ $icon := default .Pre .Params.Icon }}
4344
{{ if .Pre }}
44-
{{ partial "helper/icon" .Pre }}
45+
{{ warnf "Menu item [%s] is using [pre] field to set icon, please use [params.icon] instead.\nMore information: https://docs.stack.jimmycai.com/configuration/custom-menu.html" .URL }}
46+
{{ end }}
47+
{{ with $icon }}
48+
{{ partial "helper/icon" . }}
4549
{{ end }}
4650
<span>{{- .Name -}}</span>
4751
</a>

0 commit comments

Comments
 (0)