mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-14 20:37:55 -05:00
navigation: Check Page first in URL()
In Hugo #8776 we added `pageRef`, a way to connect menu items in site config to pages. This means that you now can have both a Page and a configured URL. Having the configured URL as a fallback if the Page isn't found is obviously more useful, especially in multilingual sites. See #8776
This commit is contained in:
parent
e521c9a36d
commit
32508045d3
1 changed files with 8 additions and 4 deletions
|
@ -46,15 +46,19 @@ type MenuEntry struct {
|
|||
}
|
||||
|
||||
func (m *MenuEntry) URL() string {
|
||||
if m.ConfiguredURL != "" {
|
||||
return m.ConfiguredURL
|
||||
}
|
||||
|
||||
// Check page first.
|
||||
// In Hugo 0.86.0 we added `pageRef`,
|
||||
// a way to connect menu items in site config to pages.
|
||||
// This means that you now can have both a Page
|
||||
// and a configured URL.
|
||||
// Having the configured URL as a fallback if the Page isn't found
|
||||
// is obviously more useful, especially in multilingual sites.
|
||||
if !types.IsNil(m.Page) {
|
||||
return m.Page.RelPermalink()
|
||||
}
|
||||
|
||||
return ""
|
||||
return m.ConfiguredURL
|
||||
}
|
||||
|
||||
// A narrow version of page.Page.
|
||||
|
|
Loading…
Reference in a new issue