feat: Allow post paths with slashes
This commit is contained in:
parent
7e10ac28f4
commit
80f571331a
5 changed files with 8 additions and 5 deletions
|
@ -36,7 +36,7 @@ defmodule Legendary.Content.Sitemaps do
|
||||||
if page_count > 1 do
|
if page_count > 1 do
|
||||||
(2..page_count)
|
(2..page_count)
|
||||||
|> Enum.each(fn page ->
|
|> Enum.each(fn page ->
|
||||||
add Helpers.paged_post_path(Endpoint, :show, post, page), priority: 0.5, changefreq: "hourly", expires: nil
|
add Helpers.posts_path(Endpoint, :show, post, page: page), priority: 0.5, changefreq: "hourly", expires: nil
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -58,7 +58,7 @@ defmodule Legendary.Content.PostsController do
|
||||||
conn |> index_posts(%{"id" => "blog", "page" => page_string})
|
conn |> index_posts(%{"id" => "blog", "page" => page_string})
|
||||||
end
|
end
|
||||||
|
|
||||||
def show(conn, %{"id" => id, "page" => page_string}) do
|
def show(conn, %{"id" => id, "page" => page_string}) when is_binary(id) or is_integer(id) do
|
||||||
post = Posts.get_post(id)
|
post = Posts.get_post(id)
|
||||||
|
|
||||||
if is_nil(post) do
|
if is_nil(post) do
|
||||||
|
@ -67,6 +67,9 @@ defmodule Legendary.Content.PostsController do
|
||||||
conn |> show_one(post, page_string)
|
conn |> show_one(post, page_string)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
def show(conn, %{"id" => id, "page" => page_string}) when is_list(id) do
|
||||||
|
show(conn, %{"id" => Enum.join(id, "/"), "page" => page_string})
|
||||||
|
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"})
|
||||||
|
|
||||||
defp try_static_post(conn, id) do
|
defp try_static_post(conn, id) do
|
||||||
|
|
|
@ -33,7 +33,7 @@ defmodule Legendary.Content.Routes do
|
||||||
get "/", PostsController, :index
|
get "/", PostsController, :index
|
||||||
resources "/sitemap", SitemapController, only: [:index]
|
resources "/sitemap", SitemapController, only: [:index]
|
||||||
get "/:id", PostsController, :show
|
get "/:id", PostsController, :show
|
||||||
get "/:id/:page", PostsController, :show, as: :paged_post
|
get "/*id", PostsController, :show, as: :nested_posts
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
1..Legendary.Content.Post.content_page_count(@post),
|
1..Legendary.Content.Post.content_page_count(@post),
|
||||||
fn page ->
|
fn page ->
|
||||||
if assigns[:current_page] == nil || assigns[:current_page] != page do
|
if assigns[:current_page] == nil || assigns[:current_page] != page do
|
||||||
link page, to: Routes.paged_post_path(@conn, :show, @post, page)
|
link page, to: Routes.posts_path(@conn, :show, @post, page: page)
|
||||||
else
|
else
|
||||||
content_tag :span, page, class: "paginator-page"
|
content_tag :span, page, class: "paginator-page"
|
||||||
end
|
end
|
||||||
|
|
|
@ -154,7 +154,7 @@ defmodule Legendary.Content.PostsControllerTest do
|
||||||
end
|
end
|
||||||
|
|
||||||
test "shows the post with pagination", %{conn: conn, posts: posts} do
|
test "shows the post with pagination", %{conn: conn, posts: posts} do
|
||||||
conn = get conn, Routes.paged_post_path(conn, :show, posts, "2")
|
conn = get conn, Routes.posts_path(conn, :show, posts, page: "2")
|
||||||
|
|
||||||
assert html_response(conn, 200) =~ posts.title
|
assert html_response(conn, 200) =~ posts.title
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue