PhoenixBlog (phoenix_blog v0.1.7)

Copy Markdown View Source

Plug-and-play blog engine for Phoenix with Editor.js integration.

Setup

  1. Add {:phoenix_blog, "~> 0.1"} to your mix.exs
  2. Configure: config :phoenix_blog, repo: MyApp.Repo
  3. Create and run the migration (see PhoenixBlog.Migration)
  4. Mount routes in your router (see PhoenixBlog.Web.Router)

Summary

Functions

Returns an %Ecto.Changeset{} for tracking post changes.

Returns the count of posts matching the given admin filters.

Returns the count of published posts matching the given filters.

Creates a post.

Deletes a post permanently.

Gets a single post by ID.

Gets a single published post by slug.

Gets a single post by slug (admin version, no status/deleted filters).

Returns the like count for a single post.

Returns a map of %{post_id => like_count} for a list of post IDs. Efficient batch query for feed pages.

Returns true if the user has liked the post.

Returns a MapSet of post IDs that the given user has liked from the provided list.

Returns the latest N published posts.

Returns posts for admin with optional filters and pagination.

Returns published posts for public display with pagination.

Returns all unique tags from published posts, sorted alphabetically.

Publishes a post.

Restores a soft-deleted post.

Soft deletes a post.

Toggles a like for the given post by the given user.

Updates a post.

Functions

change_post(post, attrs \\ %{})

Returns an %Ecto.Changeset{} for tracking post changes.

count_posts(opts \\ [])

Returns the count of posts matching the given admin filters.

count_published_posts(opts \\ [])

Returns the count of published posts matching the given filters.

create_post(attrs)

Creates a post.

delete_post(post)

Deletes a post permanently.

get_post!(id)

Gets a single post by ID.

Raises Ecto.NoResultsError if the post does not exist.

get_post_by_slug!(slug)

Gets a single published post by slug.

Raises Ecto.NoResultsError if the post does not exist.

get_post_by_slug_admin(slug)

Gets a single post by slug (admin version, no status/deleted filters).

like_count(post_id)

Returns the like count for a single post.

like_counts_for_posts(post_ids)

Returns a map of %{post_id => like_count} for a list of post IDs. Efficient batch query for feed pages.

liked_by_user?(post_id, user_id)

Returns true if the user has liked the post.

liked_post_ids_for_user(post_ids, user_id)

Returns a MapSet of post IDs that the given user has liked from the provided list.

list_latest_published_posts(limit \\ 4)

Returns the latest N published posts.

list_posts(opts \\ [])

Returns posts for admin with optional filters and pagination.

Options

  • :page - Page number (default: 1)
  • :per_page - Items per page (default: 20)
  • :status - Filter by status
  • :search - Search by title
  • :tag - Filter by tag
  • :show_deleted - Include soft-deleted posts (default: false)

list_published_posts(opts \\ [])

Returns published posts for public display with pagination.

Options

  • :page - Page number (default: 1)
  • :per_page - Items per page (default: 12)
  • :search - Search by title
  • :tag - Filter by tag

list_published_tags()

Returns all unique tags from published posts, sorted alphabetically.

publish_post(post)

Publishes a post.

restore_post(post)

Restores a soft-deleted post.

soft_delete_post(post)

Soft deletes a post.

toggle_like(post_id, user_id)

Toggles a like for the given post by the given user.

Returns {:ok, :liked} or {:ok, :unliked}. Requires config :phoenix_blog, likes_enabled: true.

update_post(post, attrs)

Updates a post.