PhoenixKit.Modules.Sitemap.FileStorage (phoenix_kit v1.7.71)

Copy Markdown View Source

File-based storage for sitemap XML files.

Supports both a single index file and per-module sitemap files:

priv/static/sitemap.xml                     -> sitemapindex (index)
priv/static/sitemaps/sitemap-static.xml     -> static pages
priv/static/sitemaps/sitemap-routes.xml     -> router discovery
priv/static/sitemaps/sitemap-publishing.xml -> publishing posts
priv/static/sitemaps/sitemap-shop.xml       -> shop products
priv/static/sitemaps/sitemap-entities.xml   -> entity records

Key Features

  • Direct nginx serving - Files in priv/static/ can be served without Phoenix
  • ETag from mtime - Use get_file_stat/0 for cache validation
  • On-demand generation - First request generates if file missing
  • Per-module files - Independent generation and caching per source

Summary

Functions

Clears the sitemap file. Alias for delete/0.

Deletes the sitemap file to force regeneration.

Deletes all module sitemap files in the sitemaps subdirectory.

Deletes a specific module sitemap file.

Checks if the sitemap file exists.

Returns the file path for the sitemap.

Returns file stats for ETag generation.

Returns file stats for a specific module sitemap file.

Checks if the index sitemap file exists.

Lists all .xml files in the sitemaps subdirectory.

Loads XML content from the sitemap file.

Loads XML content from the index sitemap file.

Loads XML content for a specific module sitemap file.

Checks if a specific module sitemap file exists.

Returns the full path for a module sitemap file.

Saves XML content to the sitemap file.

Saves XML content to the index sitemap file.

Saves XML content for a specific module sitemap file.

Returns the path to the sitemaps subdirectory.

Returns the storage directory path.

Functions

clear_all()

@spec clear_all() :: :ok

Clears the sitemap file. Alias for delete/0.

delete()

@spec delete() :: :ok

Deletes the sitemap file to force regeneration.

delete_all_modules()

@spec delete_all_modules() :: :ok

Deletes all module sitemap files in the sitemaps subdirectory.

delete_module(filename)

@spec delete_module(String.t()) :: :ok

Deletes a specific module sitemap file.

exists?()

@spec exists?() :: boolean()

Checks if the sitemap file exists.

file_path()

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

Returns the file path for the sitemap.

get_file_stat()

@spec get_file_stat() :: {:ok, tuple(), non_neg_integer()} | :error

Returns file stats for ETag generation.

get_module_stat(filename)

@spec get_module_stat(String.t()) :: {:ok, tuple(), non_neg_integer()} | :error

Returns file stats for a specific module sitemap file.

index_exists?()

@spec index_exists?() :: boolean()

Checks if the index sitemap file exists.

list_module_files()

@spec list_module_files() :: [String.t()]

Lists all .xml files in the sitemaps subdirectory.

Returns list of filenames without the .xml extension.

load()

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

Loads XML content from the sitemap file.

load_index()

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

Loads XML content from the index sitemap file.

load_module(filename)

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

Loads XML content for a specific module sitemap file.

module_exists?(filename)

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

Checks if a specific module sitemap file exists.

module_file_path(filename)

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

Returns the full path for a module sitemap file.

save(xml_content)

@spec save(String.t()) :: :ok | {:error, term()}

Saves XML content to the sitemap file.

Creates the storage directory if it doesn't exist.

save_index(xml_content)

@spec save_index(String.t()) :: :ok | {:error, term()}

Saves XML content to the index sitemap file.

save_module(filename, xml_content)

@spec save_module(String.t(), String.t()) :: :ok | {:error, term()}

Saves XML content for a specific module sitemap file.

Filename should NOT include the .xml extension.

Examples

FileStorage.save_module("sitemap-shop", xml_content)
# Saves to priv/static/sitemaps/sitemap-shop.xml

sitemaps_dir()

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

Returns the path to the sitemaps subdirectory.

storage_dir()

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

Returns the storage directory path.