Documentation
¶
Index ¶
- Variables
- func Canonical(routes contenturl.Routes, languages []string, language string, ...) (string, bool)
- func FromContext(ctx context.Context) (contenturl.Decision, bool)
- func ParseVersionCode(s string) (contenturl.VersionCode, error)
- func Path(languages []string, language, route string, code contenturl.Code, slug string) string
- func Prefix(languages []string, language string) string
- func ValidSlug(s string) bool
- func Versioned(path string, code contenturl.VersionCode) string
- type Options
- type Router
- type Store
- func (s *Store) Links(ctx context.Context, refs []contentref.ContentRef) (map[contentref.ContentKey]contenturl.Link, error)
- func (s *Store) Resolve(ctx context.Context, cs []contenturl.Code) (map[contenturl.Code]contenturl.Link, error)
- func (s *Store) ResolveAliases(ctx context.Context, keys []contenturl.AliasKey) ([]*contenturl.AliasMatch, error)
- func (s *Store) Versions(ctx context.Context, keys []contenturl.VersionKey) (map[contenturl.VersionKey]string, error)
Constants ¶
This section is empty.
Variables ¶
var (
ErrConflict = codes.ErrConflict
)
var ErrInvalidVersionCode = fmt.Errorf("%w: not a version code", codes.ErrInvalid)
ErrInvalidVersionCode refuses what is not a version code.
var (
ErrNotFound = codes.ErrNotFound
)
Functions ¶
func Canonical ¶
func Canonical(routes contenturl.Routes, languages []string, language string, link contenturl.Link) (string, bool)
Canonical returns link's canonical path in language (the default when ""), with its slug there; false when link's kind has no route.
func FromContext ¶
func FromContext(ctx context.Context) (contenturl.Decision, bool)
FromContext returns the decision Middleware matched for this request.
func ParseVersionCode ¶
func ParseVersionCode(s string) (contenturl.VersionCode, error)
ParseVersionCode reads a version code with ParseCode's rules.
func Path ¶
Path is a content page's path, /{language}/{route}/{code}[/{slug}], under Prefix(languages, language); slug is the caller's decorative path for that language (an entity and a title, "/"-joined). Every path ContentKit answers is built here.
func Prefix ¶
Prefix is the language of a page asked for in language on a site of languages, its default first: language, else the default. Every content page is under its language; contentkit-ui's languagePrefix mirrors this.
func Versioned ¶
func Versioned(path string, code contenturl.VersionCode) string
Versioned is path with ?v=code selecting a version; "" leaves path as is.
Types ¶
type Options ¶
type Options struct {
Pool *pgxpool.Pool
Schema string // the schema ContentKit's migrations were applied in
Tenant string
}
Options configures one tenant's Store.
type Router ¶
type Router struct {
// contains filtered or unexported fields
}
Router maps content kinds to the host's routes over a Store.
func NewRouter ¶
func NewRouter(store *Store, opts contenturl.RouterOptions) (*Router, error)
NewRouter validates the options and returns the router.
func (*Router) Decide ¶
Decide parses the request path, resolves its code and compares the path with the canonical one. A missing language prefix, a wrong route, a non-canonical code spelling, a merged code, a missing or stale slug and a trailing slash all redirect; the query (?v= included) is kept.
func (*Router) Handler ¶
Handler serves GET /{code}[?lang=xx]: the code's link and canonical path, for clients that hold only a code. Any Crockford spelling resolves; the response carries the canonical code. Unknown and hidden codes are 404 not_found, Gone content 410 gone, malformed codes 400 invalid_request. POST /aliases resolves legacy identifiers the same way, in batches. The engine serves them as the codes route group (/v1/codes).
guard binds each request's actor (the code lookup is public; an editor's draft resolves only for them).
func (*Router) Middleware ¶
Middleware canonicalizes content page requests (GET and HEAD): a non-canonical path is answered 301 with the canonical path and the query unchanged, Gone content with RouterOptions.Gone, and a canonical path reaches next with the Decision in its context (FromContext) and, when BaseURL is set, a canonical Link header. Other requests pass through.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store is one tenant's content-code registry.
func (*Store) Links ¶
func (s *Store) Links(ctx context.Context, refs []contentref.ContentRef) (map[contentref.ContentKey]contenturl.Link, error)
Links returns the link of each registered reference, keyed by ref.Key(); unregistered references are absent. Use it to render lists.
func (*Store) Resolve ¶
func (s *Store) Resolve(ctx context.Context, cs []contenturl.Code) (map[contenturl.Code]contenturl.Link, error)
Resolve returns the link each code names, following merges to the survivor; a code the tenant does not have is absent. A code not in canonical form is ErrInvalidCode.
func (*Store) ResolveAliases ¶
func (s *Store) ResolveAliases(ctx context.Context, keys []contenturl.AliasKey) ([]*contenturl.AliasMatch, error)
ResolveAliases returns what each alias names, following merges, in keys' order: nil for one the tenant does not have.
func (*Store) Versions ¶
func (s *Store) Versions(ctx context.Context, keys []contenturl.VersionKey) (map[contenturl.VersionKey]string, error)
Versions answers the id of each key's version while it is live (published, past its publication time, its content live), as readers open it; keys naming none are left out.