mirror of
https://github.com/gohugoio/hugo.git
synced 2025-04-29 15:10:35 +03:00
parent
634481ba8c
commit
d831d2fce8
7 changed files with 151 additions and 34 deletions
|
@ -32,6 +32,7 @@ var smc = newMenuCache()
|
|||
type MenuEntry struct {
|
||||
ConfiguredURL string // The URL value from front matter / config.
|
||||
Page Page
|
||||
PageRef string // The path to the page, only relevant for site config.
|
||||
Name string
|
||||
Menu string
|
||||
Identifier string
|
||||
|
@ -63,6 +64,8 @@ type Page interface {
|
|||
Section() string
|
||||
Weight() int
|
||||
IsPage() bool
|
||||
IsSection() bool
|
||||
IsAncestor(other interface{}) (bool, error)
|
||||
Params() maps.Params
|
||||
}
|
||||
|
||||
|
@ -106,16 +109,28 @@ func (m *MenuEntry) IsEqual(inme *MenuEntry) bool {
|
|||
// IsSameResource returns whether the two menu entries points to the same
|
||||
// resource (URL).
|
||||
func (m *MenuEntry) IsSameResource(inme *MenuEntry) bool {
|
||||
if m.isSamePage(inme.Page) {
|
||||
return m.Page == inme.Page
|
||||
}
|
||||
murl, inmeurl := m.URL(), inme.URL()
|
||||
return murl != "" && inmeurl != "" && murl == inmeurl
|
||||
}
|
||||
|
||||
func (m *MenuEntry) isSamePage(p Page) bool {
|
||||
if !types.IsNil(m.Page) && !types.IsNil(p) {
|
||||
return m.Page == p
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (m *MenuEntry) MarshallMap(ime map[string]interface{}) {
|
||||
for k, v := range ime {
|
||||
loki := strings.ToLower(k)
|
||||
switch loki {
|
||||
case "url":
|
||||
m.ConfiguredURL = cast.ToString(v)
|
||||
case "pageref":
|
||||
m.PageRef = cast.ToString(v)
|
||||
case "weight":
|
||||
m.Weight = cast.ToInt(v)
|
||||
case "name":
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue