resolve

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssetRepoPath

func AssetRepoPath(cfg *schema.Config, value string) string

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 CleanPath

func CleanPath(p string) string

CleanPath trims surrounding whitespace and slashes.

func CollectionFor

func CollectionFor(cfg *schema.Config, filePath, explicit string) (schema.Collection, bool)

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

func ContentRoots(cfg *schema.Config) []string

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

func EntryKeys(cfg *schema.Config, fm map[string]any) map[string]string

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

func EntryTitle(coll schema.Collection, fm map[string]any, filePath string) string

EntryTitle resolves a collection's preview title slots against the frontmatter, falling back to a `title` field and then the file name.

func FileID

func FileID(filePath string) string

FileID is the content loader's id for a flat collection: the base name without extension.

func GlobMatch

func GlobMatch(pattern, rel string) bool

GlobMatch matches the patterns content loaders use: `*` within one segment, `**/` for any number of segments, `{a,b}` alternatives in the extension.

func InternalLinks(text string) []string

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

func IsAssetValue(v string) bool

IsAssetValue reports whether an image or file value is something the repository can contain, as opposed to an external or data URL.

func IsInternalLink(v string) bool

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

func IsKnownPath(cfg *schema.Config, urlPath string) bool

IsKnownPath reports whether a site path is declared in `knownPaths`: an exact match (trailing slash ignored) or a `prefix*` entry.

func IsLiteralMatch

func IsLiteralMatch(m string) bool

IsLiteralMatch reports whether a `match` names one file rather than a pattern.

func IsUnder

func IsUnder(filePath, dir string) bool

IsUnder reports whether filePath sits inside dir at any depth.

func KeyFromValue

func KeyFromValue(s schema.Storage, value string) (string, bool)

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

func LocaleFromFolder(filePath, collPath string, locales []string) string

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

func NormalizeURLPath(u string) string

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

func PreviewTokens(previewPath string) (unknown []string)

PreviewTokens returns the tokens a previewPath uses that the resolver does not know.

func PublicValue

func PublicValue(s schema.Storage, key string) string

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

func ReadDotted(obj map[string]any, key string) any

ReadDotted reads a (possibly dotted) key out of a map.

func Slug

func Slug(slug any, locale, fallback string) string

Slug reads the `slug` value: a string as-is (empty means home), a localized map by locale, else the fallback.

func SlugFallback

func SlugFallback(filePath, collPath string, locales []string, stripLocale bool) string

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

func StripPagination(n string) string

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

func ValidStorage(s schema.Storage) []string

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.

func ValuePath

func ValuePath(s schema.Storage, key string) string

ValuePath joins a storage-relative key with the storage's root to a repository path.

Types

This section is empty.

Jump to

Keyboard shortcuts

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