feat: Add blog posts index at /pages/blog
This commit is contained in:
parent
677febefde
commit
aa4cc1e3de
4 changed files with 70 additions and 52 deletions
|
@ -76,6 +76,10 @@ defmodule Content.Shortcodes do
|
|||
{tag_name, attrs, new_children}
|
||||
end
|
||||
|
||||
defp transform_text_nodes(comment = {:comment, _}) do
|
||||
comment
|
||||
end
|
||||
|
||||
defp processed_text(text) do
|
||||
text =
|
||||
text
|
||||
|
|
|
@ -79,6 +79,10 @@ defmodule Content.PostsController do
|
|||
|> render("show.html", post: post, page: 1, thumbs: [])
|
||||
end
|
||||
|
||||
def show(conn, %{"id" => "blog", "page" => page_string}) do
|
||||
conn |> index_posts(%{"id" => "blog", "page" => page_string})
|
||||
end
|
||||
|
||||
def show(conn, %{"id" => id, "page" => page_string}) do
|
||||
{page_id_for_posts, _} = Options.get_value_as_int("page_for_posts")
|
||||
|
||||
|
@ -87,11 +91,7 @@ defmodule Content.PostsController do
|
|||
if is_nil(post) do
|
||||
try_static_post(conn, id)
|
||||
else
|
||||
if post.id == page_id_for_posts do
|
||||
conn |> index_posts(%{"id" => id, "page" => page_string})
|
||||
else
|
||||
conn |> show_one(post, page_string)
|
||||
end
|
||||
conn |> show_one(post, page_string)
|
||||
end
|
||||
end
|
||||
def show(conn, %{"id" => id}), do: show(conn, %{"id" => id, "page" => "1"})
|
||||
|
|
|
@ -1,15 +1,17 @@
|
|||
<%= for post <- @posts do %>
|
||||
<article class="<%= post_class(post) %> h-entry">
|
||||
<h2 class="entry-title p-name">
|
||||
<%= link to: Routes.posts_path(@conn, :show, post), class: "u-url" do %>
|
||||
<%= raw post.post_title %>
|
||||
<% end %>
|
||||
</h2>
|
||||
<%= post_topmatter(@conn, post) %>
|
||||
<article class="ui text container <%= post_class(post) %> h-entry">
|
||||
<div class="ui main padded text container">
|
||||
<h1 class="ui header p-name">
|
||||
<%= link to: Routes.posts_path(@conn, :show, post), class: "u-url" do %>
|
||||
<%= raw post.post_title %>
|
||||
<% end %>
|
||||
</h1>
|
||||
<%= post_topmatter(@conn, post) %>
|
||||
</div>
|
||||
<div class="Article-content <%= if post.post_format, do: post.post_format.slug %> e-content">
|
||||
<%= if authenticated_for_post?(@conn, post) do %>
|
||||
<%= render "thumb.html", post: post, thumbs: @thumbs %>
|
||||
<div class="Article-content-words">
|
||||
<div class="Article-content-words" style="padding-bottom: 4em; padding-top: 4em;">
|
||||
<%= raw post |> Content.Post.content_page(1) |> Content.Post.before_more |> process_content |> raw %>
|
||||
<%= if post.post_content =~ "<!--more-->" do %>
|
||||
<p>
|
||||
|
@ -22,41 +24,61 @@
|
|||
<%= render "password_form.html", post: post, conn: @conn %>
|
||||
<% end %>
|
||||
</div>
|
||||
<p class="CategoryBlock">
|
||||
Categories:
|
||||
<%= for term <- post.categories do %>
|
||||
<%= link term.name, to: Routes.category_path(@conn, :index_posts, term.slug), class: "p-category" %>
|
||||
<% end %>
|
||||
</p>
|
||||
<hr />
|
||||
<div class="ui grid">
|
||||
<div class="ui center aligned one column row CategoryBlock" style="padding-top: 2rem;">
|
||||
<div class="ui column">
|
||||
<%= case post.categories || [] do %>
|
||||
<% [] -> %>
|
||||
<%= "" %>
|
||||
<% categories -> %>
|
||||
<%= for term <- categories do %>
|
||||
<div class="ui label">
|
||||
<%= link term.name, to: Routes.category_path(@conn, :index_posts, term.slug), class: "p-category" %>
|
||||
</div>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</article>
|
||||
<% end %>
|
||||
|
||||
<nav class="paginator">
|
||||
Page:
|
||||
<%= if @page > 1 do %>
|
||||
<%= link 1, to: paginated_posts_path(@conn, @category, 1) %>
|
||||
<% end %>
|
||||
<nav class="ui text container paginator">
|
||||
<div class="ui grid">
|
||||
<div class="ui center aligned one column row">
|
||||
<div class="column">
|
||||
<h3 class="ui header">
|
||||
Pages
|
||||
</h3>
|
||||
|
||||
<div class="ui buttons">
|
||||
<%= if @page > 1 do %>
|
||||
<%= link 1, to: paginated_posts_path(@conn, @category, 1), class: "ui button" %>
|
||||
<% end %>
|
||||
|
||||
<%= if @page > 3 do %>
|
||||
<span class="paginator-page">...</span>
|
||||
<% end %>
|
||||
<%= if @page > 3 do %>
|
||||
<span class="paginator-page ui button disabled">...</span>
|
||||
<% end %>
|
||||
|
||||
<%= if @page > 2 do %>
|
||||
<%= link @page - 1, to: paginated_posts_path(@conn, @category, @page - 1) %>
|
||||
<% end %>
|
||||
<%= if @page > 2 do %>
|
||||
<%= link @page - 1, to: paginated_posts_path(@conn, @category, @page - 1), class: "ui button" %>
|
||||
<% end %>
|
||||
|
||||
<span class="paginator-page"><%= @page %></span>
|
||||
<span class="paginator-page ui button disabled"><%= @page %></span>
|
||||
|
||||
<%= if @page + 1 < @last_page do %>
|
||||
<%= link @page + 1, to: paginated_posts_path(@conn, @category, @page + 1) %>
|
||||
<% end %>
|
||||
<%= if @page + 1 < @last_page do %>
|
||||
<%= link @page + 1, to: paginated_posts_path(@conn, @category, @page + 1), class: "ui button" %>
|
||||
<% end %>
|
||||
|
||||
<%= if @page + 2 < @last_page do %>
|
||||
<span class="paginator-page">...</span>
|
||||
<% end %>
|
||||
<%= if @page + 2 < @last_page do %>
|
||||
<span class="paginator-page ui button disabled">...</span>
|
||||
<% end %>
|
||||
|
||||
<%= if @page < @last_page do %>
|
||||
<%= link @last_page, to: paginated_posts_path(@conn, @category, @last_page) %>
|
||||
<% end %>
|
||||
<%= if @page < @last_page do %>
|
||||
<%= link @last_page, to: paginated_posts_path(@conn, @category, @last_page), class: "ui button" %>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
|
|
|
@ -105,14 +105,6 @@ defmodule Content.PostsControllerTest do
|
|||
post
|
||||
end
|
||||
|
||||
def fixture(:blog_page) do
|
||||
{:ok, post} = Posts.create_posts(@create_attrs)
|
||||
{:ok, _blog} = Posts.create_posts(@blog_post_attrs)
|
||||
{:ok, _option} = %Content.Option{option_name: "page_for_posts", option_value: post.id |> Integer.to_string(10)} |> Repo.insert()
|
||||
|
||||
post
|
||||
end
|
||||
|
||||
def fixture(:attachment) do
|
||||
{:ok, post} = Posts.create_posts(@attachment_attrs)
|
||||
|
||||
|
@ -184,10 +176,10 @@ defmodule Content.PostsControllerTest do
|
|||
|
||||
describe "show the blog_page" do
|
||||
test "shows the post if it is the front post", %{conn: conn} do
|
||||
page = fixture(:blog_page)
|
||||
conn = get conn, Routes.posts_path(conn, :show, page)
|
||||
post = fixture(:single_post)
|
||||
conn = get conn, Routes.posts_path(conn, :show, "blog")
|
||||
|
||||
assert html_response(conn, 200) =~ "My Blog Post"
|
||||
assert html_response(conn, 200) =~ post.post_title
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue