Documentation
¶
Index ¶
- Constants
- func BuildLocaleSwitcherContract(cfg ResolvedSiteConfig, currentPath string, requestedLocale string, ...) map[string]any
- func LocalizedPath(path, locale, defaultLocale string, mode LocalePrefixMode) string
- func LocalizedPathWithQuery(path, locale, defaultLocale string, mode LocalePrefixMode, ...) string
- func MergeViewContext(in router.ViewContext, c router.Context) router.ViewContext
- func ReadTemplateFromStack(name string, stack ...fs.FS) ([]byte, error)
- func RegisterSiteRoutes[T any](r router.Router[T], adm *admin.Admin, cfg admin.Config, siteCfg SiteConfig, ...) error
- func ResolveErrorTemplate(cfg ResolvedSiteViewConfig, code string, status int) string
- func ResolveErrorTemplateCandidates(cfg ResolvedSiteViewConfig, code string, status int) []string
- func ShouldReloadTemplates(viewCfg ResolvedSiteViewConfig, environment string) bool
- func StripSupportedLocalePrefix(path string, supported []string) (string, string)
- func TemplateFSStack(viewCfg ResolvedSiteViewConfig, defaults ...fs.FS) []fs.FS
- func ViewContextFromRequest(c router.Context) router.ViewContext
- type CanonicalRedirectMode
- type LocalePrefixMode
- type RequestState
- type ResolvedSiteConfig
- type ResolvedSiteFeatures
- type ResolvedSiteViewConfig
- type SiteConfig
- type SiteFeatures
- type SiteModule
- type SiteModuleContext
- type SiteNavigationConfig
- type SiteOption
- func WithContentHandler(handler router.HandlerFunc) SiteOption
- func WithDeliveryServices(contentSvc admin.CMSContentService, contentTypeSvc admin.CMSContentTypeService) SiteOption
- func WithSearchHandlers(pageHandler, apiHandler router.HandlerFunc) SiteOption
- func WithSearchProvider(provider admin.SearchProvider) SiteOption
- func WithSuggestHandler(handler router.HandlerFunc) SiteOption
- type SiteRuntimeError
- type SiteSearchConfig
- type SiteSearchFilterInjector
- type SiteSearchFilterRequest
- type SiteThemeConfig
- type SiteViewConfig
- type SiteViewRuntime
Constants ¶
const ( DefaultMainMenuLocation = "site.main" DefaultFallbackMenuCode = "site_main" DefaultBaseTemplate = "site/base" DefaultErrorTemplate = "site/error" DefaultSearchRoute = "/search" DefaultSearchEndpoint = "/api/v1/site/search" DefaultSearchSuggestRoute = "/api/v1/site/search/suggest" )
const ( ContributionLocalePolicyFallback = "fallback" ContributionLocalePolicyStrict = "strict" )
Variables ¶
This section is empty.
Functions ¶
func BuildLocaleSwitcherContract ¶
func BuildLocaleSwitcherContract( cfg ResolvedSiteConfig, currentPath string, requestedLocale string, resolvedLocale string, translationGroupID string, availableLocales []string, pathsByLocale map[string]string, query map[string]string, ) map[string]any
BuildLocaleSwitcherContract returns a stable template contract for language switcher rendering, preserving translation-group identity metadata.
func LocalizedPath ¶
func LocalizedPath(path, locale, defaultLocale string, mode LocalePrefixMode) string
LocalizedPath rewrites a canonical path using the configured locale prefix policy.
func LocalizedPathWithQuery ¶
func LocalizedPathWithQuery(path, locale, defaultLocale string, mode LocalePrefixMode, query map[string]string) string
LocalizedPathWithQuery rewrites a path and preserves query params.
func MergeViewContext ¶
func MergeViewContext(in router.ViewContext, c router.Context) router.ViewContext
MergeViewContext overlays request-level site context onto an existing view context.
func ReadTemplateFromStack ¶
ReadTemplateFromStack reads a template file from a multi-FS stack.
func RegisterSiteRoutes ¶
func RegisterSiteRoutes[T any]( r router.Router[T], adm *admin.Admin, cfg admin.Config, siteCfg SiteConfig, opts ...SiteOption, ) error
RegisterSiteRoutes registers quickstart site routes with deterministic ordering.
func ResolveErrorTemplate ¶
func ResolveErrorTemplate(cfg ResolvedSiteViewConfig, code string, status int) string
ResolveErrorTemplate resolves template selection in the required order: code-specific, status-specific, and finally generic fallback.
func ResolveErrorTemplateCandidates ¶
func ResolveErrorTemplateCandidates(cfg ResolvedSiteViewConfig, code string, status int) []string
ResolveErrorTemplateCandidates returns a de-duplicated chain of templates in priority order for rendering error pages.
func ShouldReloadTemplates ¶
func ShouldReloadTemplates(viewCfg ResolvedSiteViewConfig, environment string) bool
ShouldReloadTemplates reports template reload behavior for the current environment.
func StripSupportedLocalePrefix ¶
StripSupportedLocalePrefix removes a locale segment prefix from path when it matches one of the configured locales.
func TemplateFSStack ¶
func TemplateFSStack(viewCfg ResolvedSiteViewConfig, defaults ...fs.FS) []fs.FS
TemplateFSStack returns a deterministic template fallback stack.
func ViewContextFromRequest ¶
func ViewContextFromRequest(c router.Context) router.ViewContext
ViewContextFromRequest returns site view context prepared by site middleware.
Types ¶
type CanonicalRedirectMode ¶
type CanonicalRedirectMode string
CanonicalRedirectMode controls which locale is used when computing canonical redirects.
const ( // CanonicalRedirectResolvedLocale keeps existing behavior: // canonical URL locale follows the resolved record locale. CanonicalRedirectResolvedLocale CanonicalRedirectMode = "resolved_locale_canonical" // CanonicalRedirectRequestedLocaleSticky preserves the requested locale prefix // when fallback content is served. CanonicalRedirectRequestedLocaleSticky CanonicalRedirectMode = "requested_locale_sticky" )
type LocalePrefixMode ¶
type LocalePrefixMode string
LocalePrefixMode controls locale path prefix behavior.
const ( LocalePrefixNonDefault LocalePrefixMode = "non_default" LocalePrefixAlways LocalePrefixMode = "always" )
type RequestState ¶
type RequestState struct {
Locale string
DefaultLocale string
SupportedLocales []string
Environment string
ContentChannel string
AllowLocaleFallback bool
PreviewTokenPresent bool
PreviewTokenValid bool
IsPreview bool
PreviewToken string
PreviewEntityType string
PreviewContentID string
ThemeName string
ThemeVariant string
Theme map[string]map[string]string
BasePath string
AssetBasePath string
ActivePath string
ViewContext router.ViewContext
}
RequestState is the normalized per-request site runtime state.
func RequestStateFromContext ¶
func RequestStateFromContext(ctx context.Context) (RequestState, bool)
RequestStateFromContext reads request state from context.
func RequestStateFromRequest ¶
func RequestStateFromRequest(c router.Context) (RequestState, bool)
RequestStateFromRequest reads request state from request locals/context.
func ResolveRequestState ¶
func ResolveRequestState( requestCtx context.Context, c router.Context, adm *admin.Admin, _ admin.Config, siteCfg ResolvedSiteConfig, modules []SiteModule, ) (context.Context, RequestState)
ResolveRequestState computes the normalized request context + view context.
type ResolvedSiteConfig ¶
type ResolvedSiteConfig struct {
BasePath string
DefaultLocale string
SupportedLocales []string
AllowLocaleFallback bool
LocalePrefixMode LocalePrefixMode
Environment string
ContentChannel string
Views ResolvedSiteViewConfig
Search SiteSearchConfig
Modules []SiteModule
Features ResolvedSiteFeatures
Theme SiteThemeConfig
}
ResolvedSiteConfig is a normalized SiteConfig with concrete defaults.
func ResolveSiteConfig ¶
func ResolveSiteConfig(cfg admin.Config, input SiteConfig) ResolvedSiteConfig
ResolveSiteConfig normalizes runtime defaults for site registration.
type ResolvedSiteFeatures ¶
type ResolvedSiteFeatures struct {
EnablePreview bool
EnableI18N bool
EnableSearch bool
EnableTheme bool
EnableMenuDraftPreview bool
EnableCanonicalRedirect bool
CanonicalRedirectMode CanonicalRedirectMode
StrictLocalizedPaths bool
}
ResolvedSiteFeatures contains concrete runtime feature flags.
type ResolvedSiteViewConfig ¶
type ResolvedSiteViewConfig struct {
TemplateFS []fs.FS
BaseTemplate string
ErrorTemplate string
ErrorTemplatesByStatus map[int]string
ErrorTemplatesByCode map[string]string
AssetBasePath string
Reload bool
ReloadInDevelopment bool
}
ResolvedSiteViewConfig contains normalized view/runtime defaults.
type SiteConfig ¶
type SiteConfig struct {
BasePath string
DefaultLocale string
SupportedLocales []string
AllowLocaleFallback *bool
LocalePrefixMode LocalePrefixMode
Environment string
ContentChannel string
Views SiteViewConfig
Search SiteSearchConfig
Modules []SiteModule
Features SiteFeatures
Theme SiteThemeConfig
}
SiteConfig controls quickstart/site registration behavior.
type SiteFeatures ¶
type SiteFeatures struct {
EnablePreview *bool
EnableI18N *bool
EnableSearch *bool
EnableTheme *bool
EnableMenuDraftPreview *bool
EnableCanonicalRedirect *bool
CanonicalRedirectMode CanonicalRedirectMode
StrictLocalizedPaths *bool
}
SiteFeatures controls runtime feature gates.
type SiteModule ¶
type SiteModule interface {
ID() string
RegisterRoutes(ctx SiteModuleContext) error
ViewContext(ctx context.Context, in router.ViewContext) router.ViewContext
}
SiteModule allows host modules to contribute routes and view context.
type SiteModuleContext ¶
type SiteModuleContext struct {
Admin *admin.Admin
Router admin.AdminRouter
BasePath string
DefaultLocale string
ThemeEnabled bool
SearchProvider admin.SearchProvider
}
SiteModuleContext contains stable dependencies for module route registration.
type SiteNavigationConfig ¶
type SiteNavigationConfig struct {
}
SiteNavigationConfig defines site menu defaults.
type SiteOption ¶
type SiteOption func(*siteRegisterOptions)
SiteOption customizes RegisterSiteRoutes behavior.
func WithContentHandler ¶
func WithContentHandler(handler router.HandlerFunc) SiteOption
WithContentHandler overrides the default catch-all site content handler.
func WithDeliveryServices ¶
func WithDeliveryServices(contentSvc admin.CMSContentService, contentTypeSvc admin.CMSContentTypeService) SiteOption
WithDeliveryServices sets explicit content/content-type services for capability-driven site delivery handlers.
func WithSearchHandlers ¶
func WithSearchHandlers(pageHandler, apiHandler router.HandlerFunc) SiteOption
WithSearchHandlers overrides default search page/api handlers.
func WithSearchProvider ¶
func WithSearchProvider(provider admin.SearchProvider) SiteOption
WithSearchProvider sets the search provider for optional search route wiring.
func WithSuggestHandler ¶
func WithSuggestHandler(handler router.HandlerFunc) SiteOption
WithSuggestHandler overrides the default search suggest handler.
type SiteRuntimeError ¶
type SiteRuntimeError struct {
Code string
Status int
Message string
RequestedLocale string
AvailableLocales []string
ContentType string
SlugOrPath string
}
SiteRuntimeError carries normalized site error metadata used by HTML and API responses.
func (SiteRuntimeError) Error ¶
func (e SiteRuntimeError) Error() string
type SiteSearchConfig ¶
SiteSearchConfig controls optional site search routes.
type SiteSearchFilterInjector ¶
type SiteSearchFilterInjector interface {
SearchFilters(ctx context.Context, c router.Context, req SiteSearchFilterRequest) map[string][]string
}
SiteSearchFilterInjector allows modules to inject additional filter values into search and suggest provider requests.
type SiteSearchFilterRequest ¶
type SiteSearchFilterRequest struct {
Query string
Locale string
Filters map[string][]string
IsSuggest bool
}
SiteSearchFilterRequest describes the current search request state that module filter injectors can inspect before returning extra filters.
type SiteThemeConfig ¶
SiteThemeConfig controls site-level theme defaults.
type SiteViewConfig ¶
type SiteViewConfig struct {
TemplateFS []fs.FS
BaseTemplate string
ErrorTemplate string
ErrorTemplatesByStatus map[int]string
ErrorTemplatesByCode map[string]string
AssetBasePath string
Reload *bool
ReloadInDevelopment *bool
}
SiteViewConfig controls template contract defaults.
type SiteViewRuntime ¶
SiteViewRuntime captures resolved template loading + reload behavior.
func ResolveViewRuntime ¶
func ResolveViewRuntime(viewCfg ResolvedSiteViewConfig, environment string, defaults ...fs.FS) SiteViewRuntime
ResolveViewRuntime resolves template stack + reload behavior for a given environment.