Sayfa.Validator (Sayfa v0.5.0)

Copy Markdown View Source

Validates content front matter fields during build.

Emits Logger.warning/1 messages for any validation issues but does not fail the build — all warnings are non-blocking.

Uses each content type's required_fields/0 callback to determine which fields must be present, so custom content types are validated automatically.

Examples

contents = [%Sayfa.Content{title: "T", body: "", meta: %{"content_type" => "articles"}}]
Sayfa.Validator.validate_all(contents)
#=> [%Sayfa.Content{...}]  (unchanged, warnings logged)

Summary

Functions

Validates all content items, logging warnings for any issues found.

Validates a single content item, logging any warnings found.

Functions

validate_all(contents)

@spec validate_all([Sayfa.Content.t()]) :: [Sayfa.Content.t()]

Validates all content items, logging warnings for any issues found.

Returns the content list unchanged.

Examples

iex> content = %Sayfa.Content{title: "T", body: "", meta: %{"content_type" => "articles"}}
iex> Sayfa.Validator.validate_all([content]) |> length()
1

validate_one(content)

@spec validate_one(Sayfa.Content.t()) :: :ok

Validates a single content item, logging any warnings found.

Looks up the content type module from meta["content_type"] and checks all fields returned by required_fields/0.

Returns :ok regardless of whether warnings were emitted.

Examples

iex> content = %Sayfa.Content{title: "T", body: "", meta: %{"content_type" => "pages"}}
iex> Sayfa.Validator.validate_one(content)
:ok