StaticBlog.Post (StaticBlog v0.2.0)

Copy Markdown View Source

A blog post parsed by NimblePublisher from a markdown file in priv/posts/.

The filename must follow the pattern YYYY-MM-DD-slug.md. The date and slug are derived from the filename; all other fields come from the %{...} frontmatter map and the markdown body.

Summary

Functions

Build a post struct from a filename and parsed NimblePublisher attributes.

Normalize a free-form status value into one of the two atoms :published or :draft.

Parse an ISO 8601 datetime string or pass through an existing DateTime. Returns {:ok, DateTime.t()} on success, :error on unparseable input.

Like parse_datetime/1 but raises ArgumentError on invalid input.

Return a URL-safe slug for a tag name. Used to build category page URLs.

Types

status()

@type status() :: :published | :draft

t()

@type t() :: %StaticBlog.Post{
  author: String.t() | nil,
  body: String.t(),
  date: Date.t(),
  description: String.t() | nil,
  id: String.t(),
  published_at: DateTime.t(),
  slug: String.t(),
  status: status(),
  summary: String.t(),
  tags: [String.t()],
  title: String.t(),
  updated_at: DateTime.t()
}

Functions

build(filename, attrs, body)

Build a post struct from a filename and parsed NimblePublisher attributes.

Arguments

  • filename is the absolute path to the markdown file.

  • attrs is a map of the frontmatter attributes extracted by NimblePublisher.

  • body is the HTML body rendered from the markdown source.

Returns

  • A %StaticBlog.Post{} struct.

normalize_status(arg1)

@spec normalize_status(any()) :: status()

Normalize a free-form status value into one of the two atoms :published or :draft.

Accepts atoms, binaries, and nil. Any value other than a recognized draft marker is treated as :published.

parse_datetime(datetime)

@spec parse_datetime(String.t() | DateTime.t()) :: {:ok, DateTime.t()} | :error

Parse an ISO 8601 datetime string or pass through an existing DateTime. Returns {:ok, DateTime.t()} on success, :error on unparseable input.

parse_datetime!(value)

@spec parse_datetime!(String.t() | DateTime.t()) :: DateTime.t()

Like parse_datetime/1 but raises ArgumentError on invalid input.

tag_slug(tag)

@spec tag_slug(String.t()) :: String.t()

Return a URL-safe slug for a tag name. Used to build category page URLs.

Arguments

  • tag is the raw tag string as it appears in frontmatter.

Returns

  • A lowercase, dash-separated slug suitable for a URL path segment.

Examples

iex> StaticBlog.Post.tag_slug("localize")
"localize"

iex> StaticBlog.Post.tag_slug("ex_cldr")
"ex-cldr"

iex> StaticBlog.Post.tag_slug("Release Notes!")
"release-notes"