Nabo.Repo behaviour (Nabo v2.0.0) View Source
Precompiles and provides interface to interact with your posts.
defmodule MyRepo do
use Nabo.Repo, root: "priv/posts"
end
posts = MyRepo.all
{:ok, post} = MyRepo.get("foo")
post = MyRepo.get!("foo")
Can be configured with:
defmodule MyRepo do
use Nabo.Repo,
root: "priv/posts",
compiler: [
split_pattern: "<<--------->>",
front_parser: {MyJSONParser, []},
excerpt_parser: {MyExcerptParser, []},
body_parser: {Nabo.Parser.Markdown, %Earmark.Options{smartypants: false}}
]
end
:root
- the path to posts.:compiler
- the compiler options, includes of four sub-options. SeeNabo.Parser
for instructions of how to implement a parser.:split_pattern
- the delimeter that separates front-matter, excerpt and post body. This will be passed as the second argument inString.split/3
.:front_parser
- the options for parsing front matter, in{parser_module, parser_options}
format. Parser options will be passed toparse/2
function in parser module. Defaults to{Nabo.Parser.Front, []}
:excerpt_parser
- the options for parsing post excerpt, in{parser_module, parser_options}
format. Parser options will be passed toparse/2
function in parser module. Defaults to{Nabo.Parser.Markdown, []}
:body_parser
- the options for parsing post body, in{parser_module, parser_options}
format. Parser options will be passed toparse/2
function in parser module. Defaults to{Nabo.Parser.Markdown, []}
Link to this section Summary
Callbacks
Fetches all available posts in the repo.
Fetches all availables post names in the repo.
Exclude draft posts.
Filter only posts published before a specified datetime.
Finds a post by the given slug.
Similar to get/1
but raises error when no post is found.
Order posts by date.
Link to this section Callbacks
Specs
all() :: [Nabo.Post.t()]
Fetches all available posts in the repo.
Example
posts = MyRepo.all()
Specs
availables() :: [Nabo.Post.slug()]
Fetches all availables post names in the repo.
Example
availables = MyRepo.availables()
Specs
exclude_draft(posts :: [Nabo.Post.t()]) :: [Nabo.Post.t()]
Exclude draft posts.
Example
posts = MyRepo.all() |> MyRepo.exclude_draft()
Specs
filter_published(posts :: [Nabo.Post.t()], published_at :: DateTime.t()) :: [ Nabo.Post.t() ]
Filter only posts published before a specified datetime.
Example
posts = MyRepo.all() |> MyRepo.filter_published()
Specs
get(slug :: Nabo.Post.slug()) :: Nabo.Post.t() | nil
Finds a post by the given slug.
Example
MyRepo.get("my-slug")
Specs
get!(slug :: Nabo.Post.slug()) :: Nabo.Post.t()
Similar to get/1
but raises error when no post is found.
Example
post = MyRepo.get!("my-slug")
Specs
order_by_date(posts :: [Nabo.Post.t()]) :: [Nabo.Post.t()]
Order posts by date.
Example
posts = MyRepo.all() |> MyRepo.order_by_date()