fix blog tag clicks, and new post
This commit is contained in:
@@ -35,7 +35,7 @@ defmodule Blogex.Components do
|
||||
<h2>
|
||||
<a href={"#{@base_path}/#{post.id}"}>{post.title}</a>
|
||||
</h2>
|
||||
<.post_meta post={post} />
|
||||
<.post_meta post={post} base_path={@base_path} />
|
||||
</header>
|
||||
<p class="blogex-post-description">{post.description}</p>
|
||||
</article>
|
||||
@@ -49,15 +49,17 @@ defmodule Blogex.Components do
|
||||
## Attributes
|
||||
|
||||
* `:post` - a `%Blogex.Post{}` struct (required)
|
||||
* `:base_path` - base URL path for tag links (required)
|
||||
"""
|
||||
attr :post, :map, required: true
|
||||
attr :base_path, :string, required: true
|
||||
|
||||
def post_show(assigns) do
|
||||
~H"""
|
||||
<article class="blogex-post">
|
||||
<header class="blogex-post-header">
|
||||
<h1>{@post.title}</h1>
|
||||
<.post_meta post={@post} />
|
||||
<.post_meta post={@post} base_path={@base_path} />
|
||||
</header>
|
||||
<div class="blogex-post-body">
|
||||
{Phoenix.HTML.raw(@post.body)}
|
||||
@@ -68,8 +70,16 @@ defmodule Blogex.Components do
|
||||
|
||||
@doc """
|
||||
Renders post metadata (date, author, tags).
|
||||
|
||||
## Attributes
|
||||
|
||||
* `:post` - a `%Blogex.Post{}` struct (required)
|
||||
* `:base_path` - base URL path for tag links (required)
|
||||
* `:current_tag` - currently selected tag for highlighting (optional)
|
||||
"""
|
||||
attr :post, :map, required: true
|
||||
attr :base_path, :string, required: true
|
||||
attr :current_tag, :string, default: nil
|
||||
|
||||
def post_meta(assigns) do
|
||||
~H"""
|
||||
@@ -80,9 +90,13 @@ defmodule Blogex.Components do
|
||||
<span :if={@post.author} class="blogex-post-author">
|
||||
by {@post.author}
|
||||
</span>
|
||||
<span :for={tag <- @post.tags} class="blogex-tag">
|
||||
<a
|
||||
:for={tag <- @post.tags}
|
||||
href={"#{@base_path}/tag/#{tag}"}
|
||||
class={["blogex-tag-link", tag == @current_tag && "blogex-tag-active"]}
|
||||
>
|
||||
{tag}
|
||||
</span>
|
||||
</a>
|
||||
</div>
|
||||
"""
|
||||
end
|
||||
|
||||
@@ -64,7 +64,7 @@ defmodule Blogex.Layout do
|
||||
</head>
|
||||
<body style="max-width: 48rem; margin: 0 auto; padding: 2rem; font-family: system-ui, sans-serif;">
|
||||
<nav><a href={@base_path}>← Back</a></nav>
|
||||
<.post_show post={@post} />
|
||||
<.post_show post={@post} base_path={@base_path} />
|
||||
</body>
|
||||
</html>
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user