Add tag page for posts.

This commit is contained in:
Jessica Canady 2024-08-24 12:46:00 -04:00
parent 251c4b7d72
commit 1033d1d92d
Signed by: phoenix
SSH key fingerprint: SHA256:aaLOzOrLi+0n4eDZNQKH97PehwRt6KSE5fYJc+ZRKCQ
4 changed files with 28 additions and 3 deletions

View file

@ -3,7 +3,16 @@ defmodule JOLWeb.TagController do
def index(conn, _params) do
conn
|> assign(:page_title, "Jess Uses These Tags")
|> render(:index)
|> render(:index,
page_title: "Jess Uses These Tags",
tags: JOL.Blog.unique_tag_list)
end
def tag(conn, %{"tag" => tag}) do
conn
|> render(:tag,
tag: tag,
page_title: "Posts Filed Under #{tag}",
posts: JOL.Blog.get_posts_by_tag!(tag))
end
end

View file

@ -0,0 +1,5 @@
defmodule JOLWeb.TagHTML do
use JOLWeb, :html
embed_templates "tag_html/*"
end

View file

@ -0,0 +1,9 @@
<h1 class="post-title">Filed Under "<%= @tag %>"</h1>
<%= for post <- @posts do %>
<div class="post-summary">
<p class="post-date"><date><%= post.date %></date></p>
<h3> <.link href={~p"/blog/#{post.slug}"}><%= post.title %> </.link> </h3>
<p><%= raw post.lede %></p>
</div>
<% end %>

View file

@ -22,11 +22,13 @@ defmodule JOLWeb.Router do
pipe_through :browser
get "/", PageController, :home
get "/tags", TagController, :index
get "/archive", PageController, :archive
get "/about", PageController, :about
get "/now", PageController, :now
get "/tags", TagController, :index
get "/tags/:tag", TagController, :tag
get "/blog", BlogController, :index
get "/blog/:slug", BlogController, :show
end