navigation

package
v0.136.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 22, 2024 License: Apache-2.0 Imports: 10 Imported by: 5

Documentation

Overview

Package navigation provides the menu functionality.

Index

Constants

This section is empty.

Variables

View Source
var NopPageMenus = new(nopPageMenus)

Functions

func DecodeConfig added in v0.112.0

func DecodeConfig(in any) (*config.ConfigNamespace[map[string]MenuConfig, Menus], error)

func SetPageValues added in v0.112.0

func SetPageValues(m *MenuEntry, p Page)

SetPageValues sets the Page and URL values for this menu entry.

Types

type Menu []*MenuEntry

Menu is a collection of menu entries.

func (m Menu) Add(me *MenuEntry) Menu

This is for internal use only.

func (m Menu) ByName() Menu

ByName sorts the menu by the name defined in the menu configuration.

func (m Menu) ByWeight() Menu

ByWeight sorts the menu by the weight defined in the menu configuration.

func (m Menu) Clone() Menu

Clone clones the menu entries. This is for internal use only.

func (m Menu) Limit(n int) Menu

Limit limits the returned menu to n entries.

func (m Menu) Reverse() Menu

Reverse reverses the order of the menu entries.

func (m Menu) Sort() Menu

Sort sorts the menu by weight, name and then by identifier.

type MenuConfig struct {
	Identifier string
	Parent     string
	Name       string
	Pre        template.HTML
	Post       template.HTML
	URL        string
	PageRef    string
	Weight     int
	Title      string
	// User defined params.
	Params maps.Params
}

MenuConfig holds the configuration for a menu.

type MenuEntry struct {
	// The menu entry configuration.
	MenuConfig

	// The menu containing this menu entry.
	Menu string

	// The URL value from front matter / config.
	ConfiguredURL string

	// The Page connected to this menu entry.
	Page Page

	// Child entries.
	Children Menu
}

MenuEntry represents a menu item defined in either Page front matter or in the site config.

func (m *MenuEntry) HasChildren() bool

HasChildren returns whether this menu item has any children.

func (m *MenuEntry) KeyName() string

KeyName returns the key used to identify this menu entry.

func (m *MenuEntry) URL() string
type MenuQueryProvider interface {
	HasMenuCurrent(menuID string, me *MenuEntry) bool
	IsMenuCurrent(menuID string, inme *MenuEntry) bool
}

func NewMenuQueryProvider

func NewMenuQueryProvider(
	pagem PageMenusGetter,
	sitem MenusGetter,
	p Page,
) MenuQueryProvider
type Menus map[string]Menu

Menus is a dictionary of menus.

type MenusGetter interface {
	Menus() Menus
}

type Page

type Page interface {
	LinkTitle() string
	Title() string
	RelPermalink() string
	Path() string
	Section() string
	Weight() int
	IsPage() bool
	IsSection() bool
	IsAncestor(other any) bool
	Params() maps.Params
}

A narrow version of page.Page.

type PageMenus map[string]*MenuEntry

PageMenus is a dictionary of menus defined in the Pages.

func PageMenusFromPage(ms any, p Page) (PageMenus, error)
type PageMenusGetter interface {
	Menus() PageMenus
}
type PageMenusProvider interface {
	PageMenusGetter
	MenuQueryProvider
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL