diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2023-01-04 18:24:36 +0100 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2023-05-16 18:01:29 +0200 |
commit | 241b21b0fd34d91fccb2ce69874110dceae6f926 (patch) | |
tree | d4e0118eac7e9c42f065815447a70805f8d6ad3e /navigation/pagemenus.go | |
parent | 6aededf6b42011c3039f5f66487a89a8dd65e0e7 (diff) |
Create a struct with all of Hugo's config options
Primary motivation is documentation, but it will also hopefully simplify the code.
Also,
* Lower case the default output format names; this is in line with the custom ones (map keys) and how
it's treated all the places. This avoids doing `stringds.EqualFold` everywhere.
Closes #10896
Closes #10620
Diffstat (limited to 'navigation/pagemenus.go')
-rw-r--r-- | navigation/pagemenus.go | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/navigation/pagemenus.go b/navigation/pagemenus.go index 7b4f6f648..9c368f3ab 100644 --- a/navigation/pagemenus.go +++ b/navigation/pagemenus.go @@ -18,6 +18,7 @@ import ( "github.com/gohugoio/hugo/common/maps" "github.com/gohugoio/hugo/common/types" + "github.com/mitchellh/mapstructure" "github.com/spf13/cast" ) @@ -54,7 +55,8 @@ func PageMenusFromPage(p Page) (PageMenus, error) { return nil, nil } - me := MenuEntry{Page: p, Name: p.LinkTitle(), Weight: p.Weight()} + me := MenuEntry{} + SetPageValues(&me, p) // Could be the name of the menu to attach it to mname, err := cast.ToStringE(ms) @@ -87,17 +89,17 @@ func PageMenusFromPage(p Page) (PageMenus, error) { } for name, menu := range menus { - menuEntry := MenuEntry{Page: p, Name: p.LinkTitle(), Weight: p.Weight(), Menu: name} + menuEntry := MenuEntry{Menu: name} if menu != nil { ime, err := maps.ToStringMapE(menu) if err != nil { return pm, wrapErr(err) } - - if err = menuEntry.MarshallMap(ime); err != nil { - return pm, wrapErr(err) + if err := mapstructure.WeakDecode(ime, &menuEntry.MenuConfig); err != nil { + return pm, err } } + SetPageValues(&menuEntry, p) pm[name] = &menuEntry } |