Skip to content

Conversation

@lenucksi
Copy link
Contributor

@lenucksi lenucksi commented Sep 17, 2025

Summary

  • Enable Hugo's native menu system (Site.Menus.main and Site.Menus.footer) alongside existing manual data file approach for better i18n support
  • Add support for Site.Menus.main with proper parent-child relationships via .HasChildren and .Children
  • Add support for Site.Menus.footer for footer navigation
  • Use relLangURL for language-aware URL generation that works regardless of default language setting
  • Maintain full backward compatibility with existing data//header.yaml approach

Benefits

  • Better Hugo native i18n support using standard menu configuration
  • Language-aware URLs that work regardless of default language setting
  • Proper parent-child menu relationships via Hugo's menu system
  • Backward compatible - existing sites continue working unchanged
  • Enables proper multilingual navigation without hardcoded URLs

Usage Example

# hugo.yaml
languages:
  en:
    menus:
      main:
        - name: About
          url: /about/
          weight: 10
        - name: Services  
          url: /services/
          weight: 20
        - name: Contact
          url: /contact/
          parent: services
          weight: 21
      footer:
        - name: Privacy
          url: /privacy/
          weight: 10

Implementation

  • Templates check for Site.Menus.main/footer first, fall back to legacy data files
  • Proper active state detection for both simple and nested menu items
  • Full relLangURL usage for multilingual URL support
  • Maintains existing CSS classes and structure

Notice:

  • I have changed these things in a website based on your template repo (thanks a lot for it!), it works properly there. Intent there was to get rid of the data/header.yaml files and some fiddling with URLs.
  • I then asked Claude to extract my changes from the original I use to a more anonymized version that might be upstream worthy. Claude appears to have put in these "you may also use the old version" parts, I have entirely removed menu i18n based on the old system.
  • Maybe it's useful, maybe it isn't (it is at least for me) so feel free to just close it or tweak it (e.g. by also ripping out the old approach) such that it becomes merge-worthy.
    -> 🤖 Generated with Claude Code

Enable Hugo's native menu system (Site.Menus.main and Site.Menus.footer)
alongside existing manual data file approach for better i18n support.

- Add support for Site.Menus.main with proper parent-child relationships
- Add support for Site.Menus.footer for footer navigation
- Use relLangURL for language-aware URL generation
- Maintain backward compatibility with existing data/<lang>/header.yaml approach
- Enable proper multilingual navigation without hardcoded URLs

Benefits:
- Better Hugo native i18n support
- Language-aware URLs that work regardless of default language setting
- Proper parent-child menu relationships via Hugo's menu system
- Backward compatible - existing sites continue working unchanged

Usage example in hugo.yaml:
languages:
  en:
    menus:
      main:
        - name: About
          url: /about/
          weight: 10
        - name: Services
          url: /services/
          weight: 20
        - name: Contact
          url: /contact/
          parent: services
          weight: 21
      footer:
        - name: Privacy
          url: /privacy/
          weight: 10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant