blogit v1.1.1 Blogit.Models.Post.Meta View Source

Represents the meta-data of a post.

Provides a function to read/parse the meta information from a file. All the meta-fields have default values.

The meta information can be stored at the top of the markdown file’s content in YAML format. The markdown content and meta-data are divided using the ---. This yml meta data has the highest priority when Blogit.Models.Post.Meta struct is created from a post source file.

With lower priority are the defaults and values read from the repository containing the file.

Link to this section Summary

Functions

Creates a Blogit.Models.Post.Meta struct using the source file of a post, its raw data, the language of the post, the name of the post and the repository containing the blog data

Sorts a list of Blogit.Models.Post.Meta strucs by the given field. The field can be either :created_at or updated_at

Link to this section Types

Link to this type t() View Source
t() :: %Blogit.Models.Post.Meta{author: String.t, category: String.t, created_at: Calendar :: NaiveDateTime.t, language: String.t, month: String.t, name: String.t, pinned: boolean, preview: String.t, published: boolean, tags: [String.t], title: String.t, title_image_path: String.t, updated_at: Calendar :: NaiveDateTime.t, year: String.t}

Link to this section Functions

Link to this function from_file(file_path, repository, raw_data, name, language) View Source

Creates a Blogit.Models.Post.Meta struct using the source file of a post, its raw data, the language of the post, the name of the post and the repository containing the blog data.

The given raw_meta should be list with two elements, the first element should be an YAML string containing the meta-data and the second the post’s raw content.

Link to this function sorted(metas, field \\ :created_at) View Source
sorted([t], atom) :: [t]

Sorts a list of Blogit.Models.Post.Meta strucs by the given field. The field can be either :created_at or updated_at.

By default this field is created_at. Note that the sort is descending.

Examples

iex> alias Blogit.Models.Post.Meta
iex> metas = [
...>   %Meta{created_at: ~N[2017-02-14 22:23:12], name: "meta1"},
...>   %Meta{created_at: ~N[2017-04-22 14:53:45], name: "meta2"},
...>   %Meta{created_at: ~N[2017-03-01 07:42:56], name: "meta3"}
...> ]
iex> Meta.sorted(metas) |> Enum.map(fn (meta) -> meta.name end)
~w[meta2 meta3 meta1]

iex> alias Blogit.Models.Post.Meta
iex> metas = [
...>   %Meta{updated_at: ~N[2017-03-01 07:42:56], name: "meta2"},
...>   %Meta{updated_at: ~N[2017-02-14 22:23:12], name: "meta1"},
...>   %Meta{updated_at: ~N[2017-04-20 12:23:12], name: "meta3"}
...> ]
iex> Meta.sorted(metas, :updated_at) |> Enum.map(&(&1.name))
~w[meta3 meta2 meta1]