Merge branch 'blog-index' into 'master'

feat: Add blog posts index at /pages/blog

See merge request mythic-insight/legendary!8
This commit is contained in:
Robert Prehn 2020-07-27 23:32:05 +00:00
commit 8ee25a6632
4 changed files with 70 additions and 52 deletions

View file

@ -76,6 +76,10 @@ defmodule Content.Shortcodes do
{tag_name, attrs, new_children} {tag_name, attrs, new_children}
end end
defp transform_text_nodes(comment = {:comment, _}) do
comment
end
defp processed_text(text) do defp processed_text(text) do
text = text =
text text

View file

@ -79,6 +79,10 @@ defmodule Content.PostsController do
|> render("show.html", post: post, page: 1, thumbs: []) |> render("show.html", post: post, page: 1, thumbs: [])
end 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 def show(conn, %{"id" => id, "page" => page_string}) do
{page_id_for_posts, _} = Options.get_value_as_int("page_for_posts") {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 if is_nil(post) do
try_static_post(conn, id) try_static_post(conn, id)
else else
if post.id == page_id_for_posts do conn |> show_one(post, page_string)
conn |> index_posts(%{"id" => id, "page" => page_string})
else
conn |> show_one(post, page_string)
end
end end
end end
def show(conn, %{"id" => id}), do: show(conn, %{"id" => id, "page" => "1"}) def show(conn, %{"id" => id}), do: show(conn, %{"id" => id, "page" => "1"})

View file

@ -1,15 +1,17 @@
<%= for post <- @posts do %> <%= for post <- @posts do %>
<article class="<%= post_class(post) %> h-entry"> <article class="ui text container <%= post_class(post) %> h-entry">
<h2 class="entry-title p-name"> <div class="ui main padded text container">
<%= link to: Routes.posts_path(@conn, :show, post), class: "u-url" do %> <h1 class="ui header p-name">
<%= raw post.post_title %> <%= link to: Routes.posts_path(@conn, :show, post), class: "u-url" do %>
<% end %> <%= raw post.post_title %>
</h2> <% end %>
<%= post_topmatter(@conn, post) %> </h1>
<%= post_topmatter(@conn, post) %>
</div>
<div class="Article-content <%= if post.post_format, do: post.post_format.slug %> e-content"> <div class="Article-content <%= if post.post_format, do: post.post_format.slug %> e-content">
<%= if authenticated_for_post?(@conn, post) do %> <%= if authenticated_for_post?(@conn, post) do %>
<%= render "thumb.html", post: post, thumbs: @thumbs %> <%= 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 %> <%= raw post |> Content.Post.content_page(1) |> Content.Post.before_more |> process_content |> raw %>
<%= if post.post_content =~ "<!--more-->" do %> <%= if post.post_content =~ "<!--more-->" do %>
<p> <p>
@ -22,41 +24,61 @@
<%= render "password_form.html", post: post, conn: @conn %> <%= render "password_form.html", post: post, conn: @conn %>
<% end %> <% end %>
</div> </div>
<p class="CategoryBlock"> <div class="ui grid">
Categories: <div class="ui center aligned one column row CategoryBlock" style="padding-top: 2rem;">
<%= for term <- post.categories do %> <div class="ui column">
<%= link term.name, to: Routes.category_path(@conn, :index_posts, term.slug), class: "p-category" %> <%= case post.categories || [] do %>
<% end %> <% [] -> %>
</p> <%= "" %>
<hr /> <% 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> </article>
<% end %> <% end %>
<nav class="paginator"> <nav class="ui text container paginator">
Page: <div class="ui grid">
<%= if @page > 1 do %> <div class="ui center aligned one column row">
<%= link 1, to: paginated_posts_path(@conn, @category, 1) %> <div class="column">
<% end %> <h3 class="ui header">
Pages
</h3>
<%= if @page > 3 do %> <div class="ui buttons">
<span class="paginator-page">...</span> <%= if @page > 1 do %>
<% end %> <%= link 1, to: paginated_posts_path(@conn, @category, 1), class: "ui button" %>
<% end %>
<%= if @page > 2 do %> <%= if @page > 3 do %>
<%= link @page - 1, to: paginated_posts_path(@conn, @category, @page - 1) %> <span class="paginator-page ui button disabled">...</span>
<% end %> <% end %>
<span class="paginator-page"><%= @page %></span> <%= if @page > 2 do %>
<%= link @page - 1, to: paginated_posts_path(@conn, @category, @page - 1), class: "ui button" %>
<% end %>
<%= if @page + 1 < @last_page do %> <span class="paginator-page ui button disabled"><%= @page %></span>
<%= link @page + 1, to: paginated_posts_path(@conn, @category, @page + 1) %>
<% end %>
<%= if @page + 2 < @last_page do %> <%= if @page + 1 < @last_page do %>
<span class="paginator-page">...</span> <%= link @page + 1, to: paginated_posts_path(@conn, @category, @page + 1), class: "ui button" %>
<% end %> <% end %>
<%= if @page < @last_page do %> <%= if @page + 2 < @last_page do %>
<%= link @last_page, to: paginated_posts_path(@conn, @category, @last_page) %> <span class="paginator-page ui button disabled">...</span>
<% end %> <% 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> </nav>

View file

@ -105,14 +105,6 @@ defmodule Content.PostsControllerTest do
post post
end 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 def fixture(:attachment) do
{:ok, post} = Posts.create_posts(@attachment_attrs) {:ok, post} = Posts.create_posts(@attachment_attrs)
@ -184,10 +176,10 @@ defmodule Content.PostsControllerTest do
describe "show the blog_page" do describe "show the blog_page" do
test "shows the post if it is the front post", %{conn: conn} do test "shows the post if it is the front post", %{conn: conn} do
page = fixture(:blog_page) post = fixture(:single_post)
conn = get conn, Routes.posts_path(conn, :show, page) 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
end end