Fix the "posts by tag" render.
This commit is contained in:
parent
3378bc6065
commit
8dcfd6d23c
|
@ -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
|
||||||
|
|
|
@ -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 %>
|
||||||
|
|
Loading…
Reference in a new issue