Fix the "posts by tag" render.

This commit is contained in:
Jessica Canady 2024-09-24 12:37:42 -04:00
parent 3378bc6065
commit 8dcfd6d23c
Signed by: phoenix
SSH key fingerprint: SHA256:aaLOzOrLi+0n4eDZNQKH97PehwRt6KSE5fYJc+ZRKCQ
2 changed files with 14 additions and 1 deletions

View file

@ -19,4 +19,17 @@ defmodule JOL.Blog.Post do
|> validate_required([:title, :body, :slug]) |> validate_required([:title, :body, :slug])
|> cast_assoc(:tags) |> cast_assoc(:tags)
end end
def extract_lede(post) do
case Regex.named_captures(~r/(?<lede>.*)\n<!-- more -->/s, post.body) do
%{"lede" => lede} ->
lede
_ ->
post.body
|> String.split()
|> Enum.take(50)
|> Enum.join(" ")
end
end
end end

View file

@ -4,6 +4,6 @@
<div class="post-summary"> <div class="post-summary">
<p class="post-date"><date><%= post.published_at %></date></p> <p class="post-date"><date><%= post.published_at %></date></p>
<h3> <.link href={~p"/blog/#{post.slug}"}><%= post.title %> </.link> </h3> <h3> <.link href={~p"/blog/#{post.slug}"}><%= post.title %> </.link> </h3>
<p><%= raw post.lede %></p> <p><%= raw JOL.Blog.Post.extract_lede(post) %></p>
</div> </div>
<% end %> <% end %>