Documentation
¶
Overview ¶
Package menus manages navigation menus and their items.
contract.go holds the frozen wave-0 contract (types and interfaces only). The implementation arrives in wave 1.
Index ¶
- Constants
- Variables
- func ArchivePath(t *content.Type) string
- func ContentPath(it *content.Item) string
- func SafeURL(u string) bool
- func Slugify(s string) string
- func TermPath(t *taxonomy.Term) string
- type DeleteResponse
- type Item
- type ItemsRequest
- type Menu
- type Module
- type SaveRequest
- type SavedEvent
- type Service
- type ValidationError
Constants ¶
const ( // HookSaved is emitted (async) after a menu or its items change; the // payload is SavedEvent. HookSaved = "menus.saved" // FilterResolveURL runs for every item (all kinds) when a menu is read // for display; the payload is *Item with URL (and Label) already // set to the fallback. Filters may change URL/Label and must return the // *Item. FilterResolveURL = "menus.resolve_url" )
Hook names.
const ( KindCustom = "custom" KindContent = "content" KindTerm = "term" KindArchive = "archive" )
Item kinds.
Variables ¶
var DefaultLocations = []string{"primary", "footer"}
DefaultLocations are offered when the active theme declares none.
var ErrNotFound = errors.New("menus: not found")
ErrNotFound is returned for unknown menus.
Functions ¶
func ArchivePath ¶
ArchivePath is the archive URL of a content type ("/{archive_slug}/").
func ContentPath ¶
ContentPath is the fallback permalink of a content item ("/{slug}"), used only when no theme is booted: the theme Linker overwrites it through FilterResolveURL with the real permalink (/post/<slug>, /parent/child).
func SafeURL ¶
SafeURL accepts http(s), mailto and tel URLs, site-relative paths, query strings and fragments — never javascript: or other schemes.
Types ¶
type DeleteResponse ¶
DeleteResponse is returned by DELETE /v1/menus/{id}.
type Item ¶
type Item struct {
ID string `json:"id"`
MenuID string `json:"menu_id"`
ParentID string `json:"parent_id"`
Position int `json:"position"`
Label string `json:"label"`
Kind string `json:"kind"`
RefID string `json:"ref_id"`
URL string `json:"url"`
Target string `json:"target"`
CSSClass string `json:"css_class"`
OpenInNew bool `json:"open_in_new"`
Children []Item `json:"children"`
}
type ItemsRequest ¶
type ItemsRequest struct {
Items []Item `json:"items"`
}
ItemsRequest is the body of PUT /v1/menus/{id}/items.
type Module ¶
type Module struct{}
Module is the menus kernel.Module.
type SaveRequest ¶
type SaveRequest struct {
ID string `json:"id"`
Slug string `json:"slug"`
Name string `json:"name"`
Location string `json:"location"`
Locale string `json:"locale,omitempty"`
Items []Item `json:"items,omitempty"`
}
SaveRequest is the body of POST /v1/menus (create when ID is empty, update otherwise; items, when present, replace the tree).
type SavedEvent ¶
SavedEvent is the HookSaved payload.
type Service ¶
type Service interface {
List(ctx context.Context) ([]Menu, error)
Get(ctx context.Context, slug string) (*Menu, error)
ByLocation(ctx context.Context, loc string) (*Menu, error)
// ByLocationLocale is the menu at loc for locale, else the one for every locale.
ByLocationLocale(ctx context.Context, loc, locale string) (*Menu, error)
Save(ctx context.Context, m Menu) (*Menu, error)
Delete(ctx context.Context, id string) error
SaveItems(ctx context.Context, menuID string, items []Item) error
}
type ValidationError ¶
ValidationError lists invalid fields (values are i18n keys).
func (*ValidationError) Error ¶
func (e *ValidationError) Error() string