firehose/blogex/examples/blog_live_show.ex
Your Name bc14696f57 Static blog with front page summary
Goal: have a personal blog, and try out another point in the 'modular
app design with elixir' space.

Designing OTP systems with elixir had some interesting ideas.
2026-03-17 11:17:21 +00:00

52 lines
1.3 KiB
Elixir

defmodule FirehoseWeb.BlogLive.Show do
@moduledoc """
Example LiveView for showing a single blog post.
Copy this into your host app and customize the layout/styling.
"""
use MyAppWeb, :live_view
import Blogex.Components
@impl true
def mount(%{"blog" => blog_id} = _params, _session, socket) do
blog = Blogex.get_blog!(String.to_existing_atom(blog_id))
{:ok, assign(socket, :blog, blog)}
end
@impl true
def handle_params(%{"slug" => slug}, _uri, socket) do
blog = socket.assigns.blog
post = blog.get_post!(slug)
meta = Blogex.SEO.meta_tags(post, FirehoseWeb.Endpoint.url(), blog)
{:noreply,
socket
|> assign(:post, post)
|> assign(:meta, meta)
|> assign(:page_title, post.title)
|> assign(:base_path, blog.base_path())}
end
@impl true
def render(assigns) do
~H"""
<div class="max-w-3xl mx-auto py-8 px-4">
<nav class="mb-8">
<a href={@base_path} class="text-blue-600 hover:underline">
&larr; Back to {@blog.title()}
</a>
</nav>
<.post_show post={@post} />
<footer class="mt-12 pt-8 border-t border-gray-200">
<h3 class="text-lg font-semibold mb-4">Tags</h3>
<.tag_list tags={@post.tags} base_path={@base_path} />
</footer>
</div>
"""
end
end