gohugoio / hugo

The world’s fastest framework for building websites.
https://gohugo.io
Apache License 2.0
74.37k stars 7.43k forks source link

menus in config cause compile error #7915

Closed josephborg closed 3 years ago

josephborg commented 3 years ago

What version of Hugo are you using (hugo version)?

$ hugo env
Hugo Static Site Generator v0.76.5-60F0725B openbsd/amd64 BuildDate: 2020-10-14T15:17:56Z
GOOS="openbsd"
GOARCH="amd64"
GOVERSION="go1.15.1"

Does this issue reproduce with the latest release?

yes

Issue

I tried adding site-wide menus in .config. Hugo serve barfs with errors when a menu map is called from layouts, templates or partials. I'm adding an example from the documentation:

menus.yaml

menus:
  main:
  - identifier: about
    name: about hugo
    pre: <i class='fa fa-heart'></i>
    url: /about/
    weight: -110
  - name: getting started
    post: <span class='alert'>New!</span>
    pre: <i class='fa fa-road'></i>
    url: /getting-started/
    weight: -100

example layout:

{{ define "footer" }}
  <footer>
  {{ printf "%v" site.Menus.main }}
  </footer>
{{ end }}

error message from hugo serve:

INFO 2020/11/01 18:38:52 Received System Events: ["/home/user/projects/SSCMS/layouts/index.html": CHMOD "/home/user/projects/SSCMS/layouts/index.html": WRITE]

Change detected, rebuilding site.
2020-11-01 18:38:52.726 +0100
Template changed "/home/user/projects/SSCMS/layouts/index.html": WRITE
ERROR 2020/11/01 18:38:52 unable to process menus in site config
ERROR 2020/11/01 18:38:52 unable to cast map[string]interface {}{"main":[]interface {}{map[string]interface {}{"identifier":"about", "name":"about hugo", "pre":"<i class='fa fa-heart'></i>", "url":"/about/", "weight":-110}, map[string]interface {}{"name":"getting started", "post":"<span class='alert'>New!</span>", "pre":"<i class='fa fa-road'></i>", "url":"/getting-started/", "weight":-100}}} of type map[string]interface {} to []interface{}
Total in 43 ms
ERROR 2020/11/01 18:38:52 Rebuild failed:

ERROR 2020/11/01 18:38:52 Logged 2 error(s)

I'm assuming there are no stupid errors on my side. Advice solicited.

divinerites commented 3 years ago

Not sure but did you tried to indent under main ??

menus:
  main:
     - identifier: about
       name: about hugo
       pre: <i class='fa fa-heart'></i>
       url: /about/
       weight: -110
     - name: getting started
       post: <span class='alert'>New!</span>
       pre: <i class='fa fa-road'></i>
       url: /getting-started/
       weight: -100
jmooring commented 3 years ago

See your original post, and my response, here: https://discourse.gohugo.io/t/cannot-get-hugo-to-cast-menu-maps/29136

josephborg commented 3 years ago

I tried in json format and myriad indentations. it borks even on a simple declaration menus: [ "main", "footer" ].

I'll try again. this thing has me pulling my hair at this point. Seems like a simple issue and I'm blaming myself for some fundamental misunderstanding.

Not sure but did you tried to indent under main ??


menus:

  main:

     - identifier: about

       name: about hugo

       pre: <i class='fa fa-heart'></i>

       url: /about/

       weight: -110

     - name: getting started

       post: <span class='alert'>New!</span>

       pre: <i class='fa fa-road'></i>

       url: /getting-started/

       weight: -100
josephborg commented 3 years ago

I'm not sure about your suggestion. it's not very clear to me. I have tried adding the menus directive to config.yaml and menus.yaml and menus.en.yaml. The error messages around data files in general are quite cryptic for a first time hugo user. For example, in json it borks immediately for a stray comma at the end of a list.

See your original post, and my response, here:

https://discourse.gohugo.io/t/cannot-get-hugo-to-cast-menu-maps/29136

josephborg commented 3 years ago

installed a ready made theme with menus and it works. Problem lies between keyboard and seat apparently

github-actions[bot] commented 2 years ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.