Cherry.Collections.Collection behaviour (cherry v0.6.0)

Copy Markdown View Source

Behaviour for a content collection: directory + schema + routing (ADR 0003).

parse_source/2 lets a collection derive metadata from the file path itself (posts take their date and slug from YYYY-MM-DD-slug.md) before schema validation runs. route/1 maps validated metadata to the output-relative destination file.

Summary

Callbacks

Directory relative to the site root, e.g. content/posts.

Derives metadata from the source path, merged under the frontmatter.

Output-relative destination for a validated document, or nil for data-only collections (portfolio entries have no page of their own — the timeline, story, and CV views render them).

The raw NimbleOptions-style schema keyword list (introspectable).

Callbacks

dir()

@callback dir() :: String.t()

Directory relative to the site root, e.g. content/posts.

parse_source(t, map)

@callback parse_source(String.t(), map()) :: {:ok, map()} | {:error, String.t()}

Derives metadata from the source path, merged under the frontmatter.

route(t)

@callback route(Cherry.Content.Document.t()) :: String.t() | nil

Output-relative destination for a validated document, or nil for data-only collections (portfolio entries have no page of their own — the timeline, story, and CV views render them).

schema()

@callback schema() :: keyword()

The raw NimbleOptions-style schema keyword list (introspectable).