Files
Dmitry Popov 4136aaad76 Initial commit
2024-09-18 01:55:30 +04:00

12 lines
554 B
Elixir

defmodule WandererApp.Blog.Post do
@enforce_keys [:id, :author, :title, :cover_image_uri, :body, :description, :tags, :date]
defstruct [:id, :author, :title, :cover_image_uri, :body, :description, :tags, :date]
def build(filename, attrs, body) do
[year, month_day_id] = filename |> Path.rootname() |> Path.split() |> Enum.take(-2)
[month, day, id] = String.split(month_day_id, "-", parts: 3)
date = Date.from_iso8601!("#{year}-#{month}-#{day}")
struct!(__MODULE__, [id: id, date: date, body: body] ++ Map.to_list(attrs))
end
end