Search documentation of phoenix_kit

# PhoenixKitWeb.Live.Modules.Blogging (phoenix_kit v1.6.19)

View Source

Blogging module for managing site blogs and their posts.

This keeps content in the filesystem while providing an admin-friendly UI for creating timestamped markdown blog posts.

# Summary

## Types

blog()

## Functions

add_blog(name, mode \\ "timestamp", preferred_slug \\ nil)

Adds a new blog.

add_language_to_entry(blog_slug, post_path, language_code)
add_language_to_post(blog_slug, identifier, language_code)

Adds a new language file to an existing post.

blog_name(slug)

Looks up a blog name from its slug.

create_entry(blog_slug)
create_post(blog_slug, opts \\ %{})

Creates a new blog post for the given blog using the current timestamp.

disable_system()

Disables the blogging module.

enable_system()

Enables the blogging module.

enabled?()

Returns true when the blogging module is enabled.

get_blog_mode(blog_slug)

Returns the configured storage mode for a blog slug.

get_language_info(language_code)

See `PhoenixKitWeb.Live.Modules.Blogging.Storage.get_language_info/1`.

list_blogs()

Returns all configured blogs.

list_entries(blog_slug, preferred_language \\ nil)
list_posts(blog_slug, preferred_language \\ nil)

Lists blog posts for a given blog slug. Accepts optional preferred_language to show titles in user's language.

read_entry(blog_slug, relative_path)
read_post(blog_slug, identifier, language \\ nil)

Reads an existing blog post.

remove_blog(slug)

Removes a blog by slug.

slugify(name)

Generates a slug from a user-provided blog name. Returns empty string if the name contains only invalid characters.

trash_blog(slug)

Moves a blog to trash by renaming its directory with timestamp. The blog is removed from the active blogs list and its directory is renamed to: BLOGNAME-YYYY-MM-DD-HH-MM-SS

update_blog(slug, params)

Updates a blog's display name and slug.

update_entry(blog_slug, post, params)
update_post(blog_slug, post, params, opts \\ %{})

Updates a blog post and moves the file if the publication timestamp changes.

valid_slug?(slug)

Returns true when the slug matches the allowed lowercase letters, numbers, and hyphen pattern, and is not a reserved language code.

# Types

# blog()

    @type blog() :: map()

# Functions

# add_blog(name, mode \\ "timestamp", preferred_slug \\ nil)

    @spec add_blog(String.t(), String.t(), String.t() | nil) ::
      {:ok, blog()} | {:error, atom()}

Adds a new blog.

# add_language_to_entry(blog_slug, post_path, language_code)

# add_language_to_post(blog_slug, identifier, language_code)

    @spec add_language_to_post(String.t(), String.t(), String.t()) ::
      {:ok, PhoenixKitWeb.Live.Modules.Blogging.Storage.post()} | {:error, any()}

Adds a new language file to an existing post.

# blog_name(slug)

    @spec blog_name(String.t()) :: String.t() | nil

Looks up a blog name from its slug.

# create_entry(blog_slug)

# create_post(blog_slug, opts \\ %{})

    @spec create_post(String.t(), map() | keyword()) ::
      {:ok, PhoenixKitWeb.Live.Modules.Blogging.Storage.post()} | {:error, any()}

Creates a new blog post for the given blog using the current timestamp.

# disable_system()

    @spec disable_system() :: {:ok, any()} | {:error, any()}

Disables the blogging module.

# enable_system()

    @spec enable_system() :: {:ok, any()} | {:error, any()}

Enables the blogging module.

# enabled?()

    @spec enabled?() :: boolean()

Returns true when the blogging module is enabled.

# get_blog_mode(blog_slug)

    @spec get_blog_mode(String.t()) :: String.t()

Returns the configured storage mode for a blog slug.

# get_language_info(language_code)

See `PhoenixKitWeb.Live.Modules.Blogging.Storage.get_language_info/1`.

# list_blogs()

    @spec list_blogs() :: [blog()]

Returns all configured blogs.

# list_entries(blog_slug, preferred_language \\ nil)

# list_posts(blog_slug, preferred_language \\ nil)

    @spec list_posts(String.t(), String.t() | nil) :: [
      PhoenixKitWeb.Live.Modules.Blogging.Storage.post()
    ]

Lists blog posts for a given blog slug. Accepts optional preferred_language to show titles in user's language.

# read_entry(blog_slug, relative_path)

# read_post(blog_slug, identifier, language \\ nil)

    @spec read_post(String.t(), String.t(), String.t() | nil) ::
      {:ok, PhoenixKitWeb.Live.Modules.Blogging.Storage.post()} | {:error, any()}

Reads an existing blog post.

# remove_blog(slug)

    @spec remove_blog(String.t()) :: {:ok, any()} | {:error, any()}

Removes a blog by slug.

# slugify(name)

    @spec slugify(String.t()) :: String.t()

Generates a slug from a user-provided blog name. Returns empty string if the name contains only invalid characters.

# trash_blog(slug)

    @spec trash_blog(String.t()) :: {:ok, String.t()} | {:error, any()}

Moves a blog to trash by renaming its directory with timestamp. The blog is removed from the active blogs list and its directory is renamed to: BLOGNAME-YYYY-MM-DD-HH-MM-SS

# update_blog(slug, params)

    @spec update_blog(String.t(), map() | keyword()) :: {:ok, blog()} | {:error, atom()}

Updates a blog's display name and slug.

# update_entry(blog_slug, post, params)

# update_post(blog_slug, post, params, opts \\ %{})

    @spec update_post(
      String.t(),
      PhoenixKitWeb.Live.Modules.Blogging.Storage.post(),
      map(),
      map() | keyword()
    ) :: {:ok, PhoenixKitWeb.Live.Modules.Blogging.Storage.post()} | {:error, any()}

Updates a blog post and moves the file if the publication timestamp changes.

# valid_slug?(slug)

    @spec valid_slug?(String.t()) :: boolean()

Returns true when the slug matches the allowed lowercase letters, numbers, and hyphen pattern, and is not a reserved language code.

Blog slugs cannot be language codes (like 'en', 'es', 'fr') to prevent routing ambiguity.