Sayfa.Behaviours.ContentType behaviour (Sayfa v0.5.0)

Copy Markdown View Source

Behaviour for defining content types.

Content types describe how a category of content is organized: which directory it lives in, its URL prefix, default layout, and which front matter fields are required.

Examples

defmodule MyApp.ContentTypes.Recipe do
  @behaviour Sayfa.Behaviours.ContentType

  @impl true
  def name, do: :recipe

  @impl true
  def directory, do: "recipes"

  @impl true
  def url_prefix, do: "recipes"

  @impl true
  def default_layout, do: "page"

  @impl true
  def required_fields, do: [:title]
end

Summary

Callbacks

Default layout template name (without extension).

Directory name under content/ where files of this type live.

Atom identifier for this content type.

Front matter fields that must be present.

URL path prefix. Empty string for top-level pages.

Callbacks

default_layout()

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

Default layout template name (without extension).

directory()

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

Directory name under content/ where files of this type live.

name()

@callback name() :: atom()

Atom identifier for this content type.

required_fields()

@callback required_fields() :: [atom()]

Front matter fields that must be present.

url_prefix()

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

URL path prefix. Empty string for top-level pages.