Documentation
¶
Overview ¶
Package resolve answers the questions a site's layout decides: which collection a file belongs to, what URL it renders at, what repository path an image value points to, and which values in a text are links into the site. It is the Go twin of the editor's resolvers and the code the content index runs on.
Index ¶
- func AssetRepoPath(cfg *schema.Config, value string) string
- func CleanPath(p string) string
- func CollectionFor(cfg *schema.Config, filePath, explicit string) (schema.Collection, bool)
- func ContentRoots(cfg *schema.Config) []string
- func EntryKeys(cfg *schema.Config, fm map[string]any) map[string]string
- func EntryTitle(coll schema.Collection, fm map[string]any, filePath string) string
- func FileID(filePath string) string
- func GlobMatch(pattern, rel string) bool
- func InternalLinks(text string) []string
- func IsAssetValue(v string) bool
- func IsInternalLink(v string) bool
- func IsKnownPath(cfg *schema.Config, urlPath string) bool
- func IsLiteralMatch(m string) bool
- func IsUnder(filePath, dir string) bool
- func KeyFromValue(s schema.Storage, value string) (string, bool)
- func Locale(filePath string, coll schema.Collection, site schema.PreviewSite, ...) string
- func LocaleFromFolder(filePath, collPath string, locales []string) string
- func MatchRank(coll schema.Collection, filePath string) int
- func NormalizeURLPath(u string) string
- func PreviewTokens(previewPath string) (unknown []string)
- func PublicValue(s schema.Storage, key string) string
- func ReadDotted(obj map[string]any, key string) any
- func Slug(slug any, locale, fallback string) string
- func SlugFallback(filePath, collPath string, locales []string, stripLocale bool) string
- func StripPagination(n string) string
- func TemplateRoutes(coll schema.Collection) bool
- func URL(filePath string, coll schema.Collection, site schema.PreviewSite, ...) string
- func ValidStorage(s schema.Storage) []string
- func ValuePath(s schema.Storage, key string) string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssetRepoPath ¶
AssetRepoPath maps an image, file or link value to the repository path it would be served from: a storage's publicUrl or repo path, else the public directory for root-relative values, else the value as a repository path. Query strings and fragments are dropped.
func CollectionFor ¶
CollectionFor picks the collection a file belongs to: the `_collection` stamp when it names a real collection, else the collection whose `path` is the longest prefix of the file path, else `pages` when the site has it. Collections that share a path are told apart by `match`: a literal file name that equals the file's path under the directory wins, then a pattern the file matches, then the first by key.
func ContentRoots ¶
ContentRoots lists the directories content files live in: the pages directory and every collection path, sorted. Empty when the config declares none, which means the whole repository.
func EntryKeys ¶
EntryKeys collects what reference fields can look an entry up by: `slug` (a localized map flattens to `slug.<locale>`) and the site's reference key fields.
func EntryTitle ¶
EntryTitle resolves a collection's preview title slots against the frontmatter, falling back to a `title` field and then the file name.
func FileID ¶
FileID is the content loader's id for a flat collection: the base name without extension.
func GlobMatch ¶
GlobMatch matches the patterns content loaders use: `*` within one segment, `**/` for any number of segments, `{a,b}` alternatives in the extension.
func InternalLinks ¶
InternalLinks returns the root-relative targets of Markdown links and images and of href/src attributes in a text, each once, in order of first appearance.
func IsAssetValue ¶
IsAssetValue reports whether an image or file value is something the repository can contain, as opposed to an external or data URL.
func IsInternalLink ¶
IsInternalLink reports whether a link value points into this site: a root-relative path. External URLs, protocol-relative URLs, anchors, mail and phone links and `{{variable}}` placeholders are not.
func IsKnownPath ¶
IsKnownPath reports whether a site path is declared in `knownPaths`: an exact match (trailing slash ignored) or a `prefix*` entry.
func IsLiteralMatch ¶
IsLiteralMatch reports whether a `match` names one file rather than a pattern.
func KeyFromValue ¶
KeyFromValue is the inverse of PublicValue: the storage-relative key a frontmatter value names, or false when the value does not belong to the storage.
func Locale ¶
func Locale(filePath string, coll schema.Collection, site schema.PreviewSite, fm map[string]any) string
Locale is the locale of a file per its collection's `localeFrom` rule, falling back to the site default.
func LocaleFromFolder ¶
LocaleFromFolder is the file's locale when it sits in a per-locale folder directly under the collection root and that folder is a declared locale (or any folder when no locales are declared).
func MatchRank ¶
func MatchRank(coll schema.Collection, filePath string) int
MatchRank says how specifically a collection's `match` claims a file under its path: 2 for a literal file name that equals it, 1 for a pattern it matches, 0 otherwise.
func NormalizeURLPath ¶
NormalizeURLPath makes two spellings of the same page comparable: no query or fragment, no repeated slashes, no trailing slash except for the root.
func PreviewTokens ¶
PreviewTokens returns the tokens a previewPath uses that the resolver does not know.
func PublicValue ¶
PublicValue composes the value that lands in frontmatter when the file `key` (storage-relative) is picked from a storage:
- publicUrl /uploads + key foo.jpg → /uploads/foo.jpg
- publicUrl https://cdn.x + key foo.jpg → https://cdn.x/foo.jpg
- no publicUrl, path src/assets + key a.svg → /src/assets/a.svg
func ReadDotted ¶
ReadDotted reads a (possibly dotted) key out of a map.
func Slug ¶
Slug reads the `slug` value: a string as-is (empty means home), a localized map by locale, else the fallback.
func SlugFallback ¶
SlugFallback is the slug a file gets when its frontmatter declares none: its path relative to the locale folder (or the collection root), without the extension, an `index` file standing for its folder. That is the id Astro's content loader gives the file. A file outside the collection root keeps the bare file name.
func StripPagination ¶
StripPagination maps a paginated path (`/blog/2`) to the page that produces it (`/blog`). Returns "" when there is no page-number suffix. Expects a normalized path.
func TemplateRoutes ¶
func TemplateRoutes(coll schema.Collection) bool
TemplateRoutes reports whether the collection derives URLs from the file (its previewPath has tokens) rather than naming one constant preview page.
func URL ¶
func URL(filePath string, coll schema.Collection, site schema.PreviewSite, fm map[string]any) string
URL returns the path the site renders a content file at, or "" when the collection declares no previewPath.
func ValidStorage ¶
ValidStorage reports what is wrong with a storage entry, in the words the service uses when it refuses the config. Empty when it is fine.
Types ¶
This section is empty.