Nabo v1.0.0 Nabo.Repo behaviour 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: "<<--------->>",
        log_level: :warn,
        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. See Nabo.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 in String.split/3.
    • :log_level - the error log level in compile time, use false to disable logging completely. Defaults to :warn.
    • :front_parser - the options for parsing front matter, in {parser_module, parser_options} format. Parser options will be passed to parse/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 to parse/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 to parse/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 was found

Order posts by date

Link to this section Callbacks

Fetches all available posts in the repo.

Example

posts = MyRepo.all()
Link to this callback availables() View Source
availables() :: List.t()

Fetches all availables post names in the repo.

Example

availables = MyRepo.availables()
Link to this callback exclude_draft(posts) View Source
exclude_draft(posts :: [Nabo.Post.t()]) :: [Nabo.Post.t()]

Exclude draft posts.

Example

posts = MyRepo.all() |> MyRepo.exclude_draft()
Link to this callback filter_published(posts, datetime) View Source
filter_published(posts :: [Nabo.Post.t()], datetime :: DateTime.t()) :: [
  Nabo.Post.t()
]

Filter only posts published before a specified datetime.

Example

posts = MyRepo.all() |> MyRepo.filter_published()
Link to this callback get(name) View Source
get(name :: String.t()) :: {:ok, Nabo.Post.t()} | {:error, any()}

Finds a post by the given slug.

Example

{:ok, post} = MyRepo.get("my-slug")

Similar to get/1 but raises error when no post was found.

Example

post = MyRepo.get!("my-slug")
Link to this callback order_by_date(posts) View Source
order_by_date(posts :: [Nabo.Post.t()]) :: [Nabo.Post.t()]

Order posts by date.

Example

posts = MyRepo.all() |> MyRepo.order_by_date()