From b6e4f0e4895e4abb5a532bc89303602e4f548ece Mon Sep 17 00:00:00 2001 From: Jimmy Cai Date: Sat, 23 Oct 2021 06:59:22 +0000 Subject: [PATCH] refactor(menu): use .Params.icon to configure menu item icon Using [pre] field will result a warning, but will keeping working for compatibility --- exampleSite/config.yaml | 2 +- exampleSite/content/page/about.md | 3 ++- exampleSite/content/page/archives.md | 3 ++- exampleSite/content/page/search.md | 3 ++- layouts/partials/sidebar/left.html | 6 +++++- 5 files changed, 12 insertions(+), 5 deletions(-) diff --git a/exampleSite/config.yaml b/exampleSite/config.yaml index a285296..d5cf58d 100644 --- a/exampleSite/config.yaml +++ b/exampleSite/config.yaml @@ -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 diff --git a/exampleSite/content/page/about.md b/exampleSite/content/page/about.md index 79898de..494cb46 100644 --- a/exampleSite/content/page/about.md +++ b/exampleSite/content/page/about.md @@ -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. diff --git a/exampleSite/content/page/archives.md b/exampleSite/content/page/archives.md index 027dfc6..2862deb 100644 --- a/exampleSite/content/page/archives.md +++ b/exampleSite/content/page/archives.md @@ -6,5 +6,6 @@ slug: "archives" menu: main: weight: -70 - pre: archives + params: + icon: archives --- diff --git a/exampleSite/content/page/search.md b/exampleSite/content/page/search.md index f54cdb5..b2a5943 100644 --- a/exampleSite/content/page/search.md +++ b/exampleSite/content/page/search.md @@ -8,5 +8,6 @@ outputs: menu: main: weight: -60 - pre: search + params: + icon: search --- \ No newline at end of file diff --git a/layouts/partials/sidebar/left.html b/layouts/partials/sidebar/left.html index 53a6655..177a4e8 100644 --- a/layouts/partials/sidebar/left.html +++ b/layouts/partials/sidebar/left.html @@ -40,8 +40,12 @@
  • + {{ $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 }} {{- .Name -}}