PhoenixKit.Modules.Posts.PostTag (phoenix_kit v1.7.62)

Copy Markdown View Source

Schema for post tags (hashtags).

Hashtag system for post categorization with auto-slugification and usage tracking. Tags are shared across all posts (not user-specific).

Fields

  • name - Display name (e.g., "Web Development")
  • slug - URL-safe slug (e.g., "web-development")
  • usage_count - How many posts use this tag (denormalized counter)

Examples

# Tag with multiple uses
%PostTag{
  id: "018e3c4a-9f6b-7890-abcd-ef1234567890",
  name: "Web Development",
  slug: "web-development",
  usage_count: 142
}

# New tag
%PostTag{
  name: "Elixir",
  slug: "elixir",
  usage_count: 0
}

Summary

Functions

Changeset for creating or updating a tag.

Decrement usage counter.

Increment usage counter.

Types

t()

@type t() :: %PhoenixKit.Modules.Posts.PostTag{
  __meta__: term(),
  inserted_at: DateTime.t() | nil,
  name: String.t(),
  posts: term(),
  slug: String.t(),
  updated_at: DateTime.t() | nil,
  usage_count: integer(),
  uuid: UUIDv7.t() | nil
}

Functions

changeset(tag, attrs)

Changeset for creating or updating a tag.

Required Fields

  • name - Tag display name
  • slug - URL-safe slug (auto-generated from name if not provided)

Validation Rules

  • Name must not be empty
  • Slug must be unique across all tags
  • Slug auto-generated from name if not provided
  • Usage count cannot be negative

decrement_usage(tag)

Decrement usage counter.

increment_usage(tag)

Increment usage counter.