After asking this question and learning that it was beyond the scope of the support forum, I wonder if this could be added like a feature in the future:
- get the structure of a menu via getJSON from an external source (such as a headless CMS)
- add it to .Site.menus, thus making it available for site generation.
This would empower the admin of the CMS to modify his menu(s) at will and see the changes reflected in Hugo acting as a frontend of the said CMS.
Could this be done?
While I cannot speak for bep and whether he would add this feature I want to ask why you don’t do it the way you already did in your other issue. It won’t have the same syntax like a normal menu has, unless you can decide how the JSON structure would look like but you’re still able to load it and build a menu from it. If you’re using the menu at multiple locations, I recommend using partialCached in order to avoid building the menu again and again and thus slowing down the build
Mainly because implementing weight and children is kinda tedious, plus it’s like reinventing the wheel. So it would be nice to take advantage of the ordering and children assignment mechanism already in place.
The json structure as delivered by Drupal is what it is. Gotta live with it.
Thanks for the caching tip!
I suppose that you could open a Github issue with your feature request and ask the Developer team.
But bear in mind that Hugo is first of all a static site generator.
I understand your point but viewing it from the developers site, bep would also have to implement weight etc again for the JSON, it does not come naturally. Also, you say that the JSON structure is defined by drupal so you cannot change it. In order to support this in hugo, I would imagine that bep would define a more general/standard structure of the JSON because otherwise you would have to implement multiple structures because other CMS could export the file differently so in order to provide general support for this, one would have to implement a lot of things.
The whole situation would be different if hugo would provide a plugin structure as you could then implement a plugin which parses drupal menu files and provide the necessary native menu structure. I think this would be the better way but a plugin interface will probably not come until much later
Thanks for the perspective.
In this case, maybe a script outside Hugo that would alter the Hugo config file when detecting changes in the json served by Drupal could be a viable approach.
I imagine this could work. If my brain doesn’t leave alone and I’m remembering this correctly you can define and use multiple configuration files which will then be merged during build so I could imagine that a build tool like jenkins could do the parsing and then write the menu to a separate config which could then be used in conjunction with the main config to instruct hugo to build the site. Unfortunately this is all I can tell you as I’m currently lacking the necessary skills in using jenkins in order to help you further setting it up, but it should not be that hard to achieve in some way, regardless of the tool you want to usw
Also you can do this with a bash script.
Why not? Assuming Linux is the server’s OS.
Maybe something OS-server-independent could work too.
I’ll keep you posted
Personally, I like Node.JS because it is one language for front and back-end programming and because of the power of the included tools like npm (which can act as a task runner) and npx. For Windows users, Node.JS is easy to install, easy to run and has lots of support. BASH not quite so convenient for Windows but likely available to the majority of people who use Hugo via Windows (through GIT), also available as the Linux subsystem. PowerShell I don’t recommend unless you happen to need its particular powers. The other dev languages and task runners tend to get more complex in my view.
Sorry, I’m rambling, I’ll shut up now.
4 now, turns out that the easiest way to do it outside Hugo is … inside Drupal
After all, it’s php wrappers (almost) all the way. Plus integrated cron…