Filter future-dated posts from public views and add unfiltered post access
- all_posts/0 now excludes posts where date > today - all_tags/0 computed at runtime from filtered posts - posts_by_tag/1 and recent_posts/1 inherit date filtering - Add unfiltered_posts/0 to Blog macro and FakeBlog - Add all_posts_unfiltered/0 to Registry for dashboard use
This commit is contained in:
@@ -119,5 +119,6 @@ defmodule Blogex do
|
||||
defdelegate get_blog!(blog_id), to: Blogex.Registry
|
||||
defdelegate get_blog(blog_id), to: Blogex.Registry
|
||||
defdelegate all_posts, to: Blogex.Registry
|
||||
defdelegate all_posts_unfiltered, to: Blogex.Registry
|
||||
defdelegate all_tags, to: Blogex.Registry
|
||||
end
|
||||
|
||||
@@ -73,12 +73,17 @@ defmodule Blogex.Blog do
|
||||
@doc "Returns the base URL path for this blog."
|
||||
def base_path, do: @blog_base_path
|
||||
|
||||
@doc "Returns all compiled posts regardless of published status or date."
|
||||
def unfiltered_posts, do: @posts
|
||||
|
||||
@doc "Returns all visible posts, newest first. Drafts are included in dev/test."
|
||||
def all_posts do
|
||||
today = Date.utc_today()
|
||||
|
||||
if Blogex.show_drafts?() do
|
||||
@posts
|
||||
Enum.filter(@posts, &(not Date.after?(&1.date, today)))
|
||||
else
|
||||
Enum.filter(@posts, & &1.published)
|
||||
Enum.filter(@posts, &(&1.published and not Date.after?(&1.date, today)))
|
||||
end
|
||||
end
|
||||
|
||||
@@ -86,7 +91,12 @@ defmodule Blogex.Blog do
|
||||
def recent_posts(n \\ 5), do: Enum.take(all_posts(), n)
|
||||
|
||||
@doc "Returns all unique tags across all published posts."
|
||||
def all_tags, do: @tags
|
||||
def all_tags do
|
||||
all_posts()
|
||||
|> Enum.flat_map(& &1.tags)
|
||||
|> Enum.uniq()
|
||||
|> Enum.sort()
|
||||
end
|
||||
|
||||
@doc "Returns all published posts matching the given tag."
|
||||
def posts_by_tag(tag) do
|
||||
|
||||
@@ -37,6 +37,13 @@ defmodule Blogex.Registry do
|
||||
|> Enum.sort_by(& &1.date, {:desc, Date})
|
||||
end
|
||||
|
||||
@doc "Returns all posts from all blogs (unfiltered), sorted newest first."
|
||||
def all_posts_unfiltered do
|
||||
blogs()
|
||||
|> Enum.flat_map(& &1.unfiltered_posts())
|
||||
|> Enum.sort_by(& &1.date, {:desc, Date})
|
||||
end
|
||||
|
||||
@doc "Returns all unique tags across all blogs."
|
||||
def all_tags do
|
||||
blogs()
|
||||
|
||||
Reference in New Issue
Block a user