diff --git a/assets/css/style.css b/assets/css/style.css index b45a2e9..70288bf 100644 --- a/assets/css/style.css +++ b/assets/css/style.css @@ -711,3 +711,14 @@ div.homepage { grid-template-columns: repeat(auto-fill, minmax(20em, 1fr)); grid-gap: 3em; } + +ul.posts { + list-style-type: none; + margin: 0; + padding: 0; +} + +div.post_summary { + margin-bottom: 1em; + padding: 0.5rem; +} diff --git a/lib/jol/blog/post.ex b/lib/jol/blog/post.ex index fe35a33..f3c5383 100644 --- a/lib/jol/blog/post.ex +++ b/lib/jol/blog/post.ex @@ -1,8 +1,25 @@ defmodule JOL.Blog.Post do - @enforce_keys [:author, :title, :body, :tags, :date, :slug] - defstruct [:author, :draft, :title, :body, :tags, :date, :slug] + @enforce_keys [:author, :title, :body, :tags, :date, :slug, :lede] + defstruct [:author, :draft, :title, :body, :tags, :date, :slug, :lede] def build(_filename, attrs, body) do - struct!(__MODULE__, [author: "Jessica Phoenix Canady", body: body] ++ Map.to_list(attrs)) + struct!( + __MODULE__, + [author: "Jessica Phoenix Canady", body: body, lede: extract_lede(body)] ++ + Map.to_list(attrs) + ) + end + + defp extract_lede(text) do + case Regex.named_captures(~r/(?.*)\n/s, text) do + %{"lede" => lede} -> + lede + + _ -> + text + |> String.split() + |> Enum.take(50) + |> Enum.join(" ") + end end end diff --git a/lib/jol_web/components/layouts/app.html.heex b/lib/jol_web/components/layouts/app.html.heex index 040fefb..0eb7555 100644 --- a/lib/jol_web/components/layouts/app.html.heex +++ b/lib/jol_web/components/layouts/app.html.heex @@ -14,9 +14,9 @@