menus

package
v0.19.0 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: AGPL-3.0 Imports: 27 Imported by: 0

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

View Source
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.

View Source
const (
	KindCustom  = "custom"
	KindContent = "content"
	KindTerm    = "term"
	KindArchive = "archive"
)

Item kinds.

Variables

View Source
var DefaultLocations = []string{"primary", "footer"}

DefaultLocations are offered when the active theme declares none.

View Source
var ErrNotFound = errors.New("menus: not found")

ErrNotFound is returned for unknown menus.

Functions

func ArchivePath

func ArchivePath(t *content.Type) string

ArchivePath is the archive URL of a content type ("/{archive_slug}/").

func ContentPath

func ContentPath(it *content.Item) string

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

func SafeURL(u string) bool

SafeURL accepts http(s), mailto and tel URLs, site-relative paths, query strings and fragments — never javascript: or other schemes.

func Slugify

func Slugify(s string) string

Slugify makes a URL-safe slug from s (ASCII letters and digits; other runs become "-"). Names without Latin letters or digits yield "".

func TermPath

func TermPath(t *taxonomy.Term) string

TermPath is the fallback permalink of a term ("/{taxonomy}/{slug}").

Types

type DeleteResponse

type DeleteResponse struct {
	ID      string `json:"id"`
	Deleted bool   `json:"deleted"`
}

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 Menu struct {
	ID       string `json:"id"`
	Slug     string `json:"slug"`
	Name     string `json:"name"`
	Location string `json:"location"`
	Locale   string `json:"locale"` // the public-site locale it is for; "" = every locale
	Items    []Item `json:"items"`
}

type Module

type Module struct{}

Module is the menus kernel.Module.

func New

func New() *Module

New returns the menus module.

func (*Module) Catalogs

func (*Module) Catalogs() fs.FS

Catalogs implements kernel.CatalogProvider.

func (*Module) Migrations

func (*Module) Migrations() fs.FS

Migrations implements kernel.Module.

func (*Module) Name

func (*Module) Name() string

Name implements kernel.Module.

func (*Module) Register

func (*Module) Register(d *kernel.Deps) error

Register publishes kernel.ServiceMenus and adds the admin editor (under Appearance) and the API operations. The content, taxonomy and theme services are looked up per call: they may register later or be absent.

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

type SavedEvent struct {
	ID   string `json:"id"`
	Slug string `json:"slug"`
}

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

type ValidationError struct {
	Fields map[string]string `json:"fields"`
}

ValidationError lists invalid fields (values are i18n keys).

func (*ValidationError) Error

func (e *ValidationError) Error() string

Jump to

Keyboard shortcuts

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