mirror of
https://github.com/wanderer-industries/wanderer
synced 2026-05-01 15:00:31 +00:00
12 lines
554 B
Elixir
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
|