Path utilities for Pages module.
Handles path resolution, validation, and conversion operations.
Summary
Functions
Builds the full absolute path for a relative pages path.
Converts a relative file path to a slug (without .md extension).
Joins path segments safely for pages paths.
Normalizes a slug to ensure proper formatting.
Gets the root directory path for pages.
Validates that a path is safe and doesn't attempt directory traversal.
Converts a slug to a relative file path with .md extension.
Functions
Builds the full absolute path for a relative pages path.
Includes security checks to prevent directory traversal.
Examples
iex> PhoenixKit.Pages.Paths.build_full_path("/hello.md")
"/app/priv/static/pages/hello.md"
Converts a relative file path to a slug (without .md extension).
Examples
iex> PhoenixKit.Pages.Paths.file_path_to_slug("/hello.md")
"/hello"
iex> PhoenixKit.Pages.Paths.file_path_to_slug("/hello")
"/hello"
Joins path segments safely for pages paths.
Normalizes the result to ensure consistent formatting.
Examples
iex> PhoenixKit.Pages.Paths.join_path("/blog", "hello.md")
"/blog/hello.md"
iex> PhoenixKit.Pages.Paths.join_path("/blog/", "/hello.md")
"/blog/hello.md"
Normalizes a slug to ensure proper formatting.
- Ensures slug starts with "/"
- Removes trailing "/"
- Returns default slug for empty or invalid inputs
Examples
iex> PhoenixKit.Pages.Paths.normalize_slug("")
"/404"
iex> PhoenixKit.Pages.Paths.normalize_slug("hello")
"/hello"
iex> PhoenixKit.Pages.Paths.normalize_slug("/hello/")
"/hello"
Gets the root directory path for pages.
Creates the directory if it doesn't exist. Uses the parent application's directory, not PhoenixKit's dependency directory.
Examples
iex> PhoenixKit.Pages.Paths.root_path()
"/path/to/app/priv/static/pages"
Validates that a path is safe and doesn't attempt directory traversal.
Examples
iex> PhoenixKit.Pages.Paths.safe_path?("/hello")
true
iex> PhoenixKit.Pages.Paths.safe_path?("/../etc/passwd")
false
Converts a slug to a relative file path with .md extension.
Examples
iex> PhoenixKit.Pages.Paths.slug_to_file_path("/hello")
"/hello.md"
iex> PhoenixKit.Pages.Paths.slug_to_file_path("/hello.md")
"/hello.md"