45 lines
1.2 KiB
Elixir
45 lines
1.2 KiB
Elixir
defmodule Llmex.IndexLayout do
|
|
use Tableau.Layout, layout: Llmex.RootLayout
|
|
use Phoenix.Component
|
|
|
|
def template(assigns) do
|
|
~H"""
|
|
<h1><%= @page[:title] || "Latest Posts" %></h1>
|
|
|
|
<%= if @page[:description] do %>
|
|
<p><%= @page[:description] %></p>
|
|
<% end %>
|
|
|
|
<%= if assigns[:posts] && length(@posts) > 0 do %>
|
|
<ul>
|
|
<%= for post <- @posts do %>
|
|
<li>
|
|
<h2><a href={post.permalink}><%= post.title %></a></h2>
|
|
<%= if post[:date] do %>
|
|
<time datetime={post[:date]}><%= format_date(post[:date]) %></time>
|
|
<% end %>
|
|
<%= if post[:description] do %>
|
|
<p><%= post[:description] %></p>
|
|
<% end %>
|
|
</li>
|
|
<% end %>
|
|
</ul>
|
|
<% else %>
|
|
<p>No posts found.</p>
|
|
<% end %>
|
|
|
|
<%= {:safe, render(@inner_content)} %>
|
|
"""
|
|
end
|
|
|
|
defp format_date(date_string) when is_binary(date_string) do
|
|
case Date.from_iso8601(date_string) do
|
|
{:ok, date} -> Calendar.strftime(date, "%B %d, %Y")
|
|
{:error, _} -> date_string
|
|
end
|
|
end
|
|
|
|
defp format_date(%Date{} = date), do: Calendar.strftime(date, "%B %d, %Y")
|
|
defp format_date(_), do: ""
|
|
end
|