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 recordsKey Features
- Direct nginx serving - Files in priv/static/ can be served without Phoenix
- ETag from mtime - Use
get_file_stat/0for 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
@spec clear_all() :: :ok
Clears the sitemap file. Alias for delete/0.
@spec delete() :: :ok
Deletes the sitemap file to force regeneration.
@spec delete_all_modules() :: :ok
Deletes all module sitemap files in the sitemaps subdirectory.
@spec delete_module(String.t()) :: :ok
Deletes a specific module sitemap file.
@spec exists?() :: boolean()
Checks if the sitemap file exists.
@spec file_path() :: String.t()
Returns the file path for the sitemap.
@spec get_file_stat() :: {:ok, tuple(), non_neg_integer()} | :error
Returns file stats for ETag generation.
@spec get_module_stat(String.t()) :: {:ok, tuple(), non_neg_integer()} | :error
Returns file stats for a specific module sitemap file.
@spec index_exists?() :: boolean()
Checks if the index sitemap file exists.
@spec list_module_files() :: [String.t()]
Lists all .xml files in the sitemaps subdirectory.
Returns list of filenames without the .xml extension.
@spec load() :: {:ok, String.t()} | :error
Loads XML content from the sitemap file.
@spec load_index() :: {:ok, String.t()} | :error
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.
Creates the storage directory if it doesn't exist.
Saves XML content to the index sitemap file.
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
@spec sitemaps_dir() :: String.t()
Returns the path to the sitemaps subdirectory.
@spec storage_dir() :: String.t()
Returns the storage directory path.