Behaviour for sitemap data sources.
Each source module must implement this behaviour to provide URL entries for sitemap generation. Sources can collect data from various PhoenixKit modules like Entities, Publishing, Pages, etc.
Implementing a Source
defmodule PhoenixKit.Modules.Sitemap.Sources.MyModule do
@behaviour PhoenixKit.Modules.Sitemap.Sources.Source
alias PhoenixKit.Modules.Sitemap.UrlEntry
@impl true
def source_name, do: :my_module
@impl true
def enabled?, do: MyModule.enabled?()
@impl true
def collect(_opts) do
if enabled?() do
# Collect URLs from your module
[
UrlEntry.new(%{
loc: "https://example.com/my-page",
lastmod: DateTime.utc_now(),
changefreq: "weekly",
priority: 0.8,
title: "My Page",
category: "My Module",
source: :my_module
})
]
else
[]
end
end
endAdding Source to Generator
After implementing the source, add it to the generator's source list
in PhoenixKit.Modules.Sitemap.Generator.collect_all_entries/2.
Summary
Callbacks
Collects all URL entries from this source.
Checks if this source is enabled and should be included in sitemap.
Returns the unique name/identifier for this source.
Functions
Safely collects entries from a source, handling errors gracefully.
Helper function to check if a source module is valid.
Callbacks
@callback collect(opts :: keyword()) :: [PhoenixKit.Modules.Sitemap.UrlEntry.t()]
Collects all URL entries from this source.
Options may include:
:language- Preferred language for content:base_url- Base URL for building full URLs
Should return an empty list if the source is disabled.
@callback enabled?() :: boolean()
Checks if this source is enabled and should be included in sitemap.
Should return false if the underlying module is disabled or if sitemap collection is turned off for this source.
@callback source_name() :: atom()
Returns the unique name/identifier for this source.
Used for logging, filtering, and organizing sitemap entries.
Functions
@spec safe_collect( module(), keyword() ) :: [PhoenixKit.Modules.Sitemap.UrlEntry.t()]
Safely collects entries from a source, handling errors gracefully.
Helper function to check if a source module is valid.
Ensures the module is loaded before checking for exported functions.