PhoenixKit.Modules.Pages.Storage.Versions (phoenix_kit v1.7.71)

Copy Markdown View Source

Version management for pages storage.

Handles version detection, listing, status management, and version creation operations for posts.

Summary

Functions

Detects whether a post directory uses versioned structure (v1/, v2/, etc.) or legacy structure (files directly in post directory).

Gets the latest published version number for a post. Checks each version's primary language file for status.

Gets the latest (highest) version number for a post.

Deprecated: Use get_published_version/2 instead.

Gets the published version number for a post. Only ONE version can have status: "published" at a time in the variant versioning model. Falls back to checking legacy is_live field for unmigrated posts.

Gets the version_created_at date for a specific version.

Gets the metadata for a specific version and language.

Gets the status of a specific version for a language.

Lists all version numbers for a slug-mode post. Returns sorted list of integers (e.g., [1, 2, 3]). For legacy posts without version directories, returns [1].

Loads version_created_at dates for all specified versions. Returns a map of version number => ISO 8601 date string.

Loads available languages for each version of a post. Returns a map of version number => list of language codes.

Loads version statuses for all versions of a post. Returns a map of version number => status.

Checks if a post has only one version.

Parse version number from directory name (e.g., "v2" -> 2)

Resolves which version directory to read from.

Resolves the version directory for listing operations. Returns {:ok, version, content_dir} or {:error, reason}.

Check if a directory name matches version pattern (v1, v2, etc.)

Checks if a version is the published (live) version.

Returns the version directory path for a post.

Functions

detect_post_structure(post_path)

@spec detect_post_structure(String.t()) :: :versioned | :legacy | :empty

Detects whether a post directory uses versioned structure (v1/, v2/, etc.) or legacy structure (files directly in post directory).

Returns:

  • :versioned if v1/ or any vN/ directory exists
  • :legacy if .phk files exist directly in the directory
  • :empty if neither exists

get_latest_published_version(group_slug, post_slug)

@spec get_latest_published_version(String.t(), String.t()) ::
  {:ok, integer()} | {:error, :not_found}

Gets the latest published version number for a post. Checks each version's primary language file for status.

get_latest_version(group_slug, post_slug)

@spec get_latest_version(String.t(), String.t()) ::
  {:ok, integer()} | {:error, :not_found}

Gets the latest (highest) version number for a post.

get_live_version(group_slug, post_slug)

This function is deprecated. Use get_published_version/2 instead.
@spec get_live_version(String.t(), String.t()) ::
  {:ok, integer()} | {:error, :not_found}

Deprecated: Use get_published_version/2 instead.

get_published_version(group_slug, post_slug)

@spec get_published_version(String.t(), String.t()) ::
  {:ok, integer()} | {:error, :not_found}

Gets the published version number for a post. Only ONE version can have status: "published" at a time in the variant versioning model. Falls back to checking legacy is_live field for unmigrated posts.

get_version_date(group_slug, post_slug, version, language)

@spec get_version_date(String.t(), String.t(), integer(), String.t()) ::
  String.t() | nil

Gets the version_created_at date for a specific version.

get_version_metadata(group_slug, post_slug, version, language)

@spec get_version_metadata(String.t(), String.t(), integer(), String.t()) ::
  {:ok, map()} | {:error, :not_found}

Gets the metadata for a specific version and language.

get_version_status(group_slug, post_slug, version, language)

@spec get_version_status(String.t(), String.t(), integer(), String.t()) ::
  String.t() | nil

Gets the status of a specific version for a language.

list_versions(group_slug, post_slug)

@spec list_versions(String.t(), String.t()) :: [integer()]

Lists all version numbers for a slug-mode post. Returns sorted list of integers (e.g., [1, 2, 3]). For legacy posts without version directories, returns [1].

load_version_dates(group_slug, post_slug, versions, primary_language \\ nil)

@spec load_version_dates(String.t(), String.t(), [integer()], String.t() | nil) :: %{
  required(integer()) => String.t() | nil
}

Loads version_created_at dates for all specified versions. Returns a map of version number => ISO 8601 date string.

load_version_languages(group_slug, post_slug, versions)

@spec load_version_languages(String.t(), String.t(), [integer()]) :: %{
  required(integer()) => [String.t()]
}

Loads available languages for each version of a post. Returns a map of version number => list of language codes.

This is useful for showing which translations exist for a specific version, e.g., to display the published version's translations in the listing.

load_version_statuses(group_slug, post_slug, versions, primary_language \\ nil)

@spec load_version_statuses(String.t(), String.t(), [integer()], String.t() | nil) ::
  %{
    required(integer()) => String.t()
  }

Loads version statuses for all versions of a post. Returns a map of version number => status.

only_version?(post_dir)

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

Checks if a post has only one version.

parse_version_number(arg1)

@spec parse_version_number(String.t()) :: integer() | nil

Parse version number from directory name (e.g., "v2" -> 2)

resolve_version_dir(post_dir, arg2, version, group_slug, post_slug)

@spec resolve_version_dir(
  String.t(),
  :versioned | :legacy | :empty,
  integer() | nil,
  String.t(),
  String.t()
) :: {:ok, integer(), String.t()} | {:error, atom()}

Resolves which version directory to read from.

resolve_version_dir_for_listing(post_path, atom, group_slug, post_slug)

@spec resolve_version_dir_for_listing(
  String.t(),
  :versioned | :legacy | :empty,
  String.t(),
  String.t()
) :: {:ok, integer(), String.t()} | {:error, atom()}

Resolves the version directory for listing operations. Returns {:ok, version, content_dir} or {:error, reason}.

version_dir?(name)

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

Check if a directory name matches version pattern (v1, v2, etc.)

version_is_published?(group_slug, post_identifier, version)

@spec version_is_published?(String.t(), String.t(), integer()) :: boolean()

Checks if a version is the published (live) version.

version_path(group_slug, post_slug, version)

@spec version_path(String.t(), String.t(), integer()) :: String.t()

Returns the version directory path for a post.