PhoenixKitEntities.SitemapSource (PhoenixKitEntities v0.2.7)

Copy Markdown View Source

Entities source for sitemap generation.

Collects published entity records from the PhoenixKit Entities system. Each entity can define its own URL pattern in settings, and individual records can be excluded via metadata.

Universal Entity Support

This source can collect ALL published entities regardless of their name. Auto-pattern generation is off by default (sitemap_entities_auto_pattern: false): only entities with a genuinely public route or a configured URL pattern are included. Enable sitemap_entities_auto_pattern to also emit a /:entity_name/:slug fallback for every published entity — read the warning under "Configuration" first.

URL Pattern Resolution

URL patterns are resolved using fallback chain:

  1. Entity-specific override: entity.settings["sitemap_url_pattern"]
  2. Router Introspection: automatic detection from parent app router
  3. Per-entity Settings: sitemap_entity_{name}_pattern
  4. Global Settings: sitemap_entities_pattern
  5. Auto-generated fallback: /:entity_name/:slug (if sitemap_entities_auto_pattern is true)

Pattern variables:

  • :slug - Record slug
  • :id - Record ID
  • :entity_name - Entity name (for global pattern)

Examples

# Entity settings override (highest priority):
# entity.settings = %{"sitemap_url_pattern" => "/blog/:slug"}
# Generates: /blog/my-article

# Router auto-detection (if parent app has route):
# live "/pages/:slug", PagesLive, :show
# Entity "page" generates: /pages/my-article

# Settings override:
# sitemap_entity_page_pattern = "/content/:slug"
# Entity "page" generates: /content/my-article

# Auto-generated fallback (opt-in; off by default):
# Entity "hydraulic_cylinder" generates: /hydraulic_cylinder/my-product
# Entity "contact_request" generates: /contact_request/request-123

Index Pages

By default, index/list pages are included for each entity (e.g., /page, /products). This can be controlled via the sitemap_entities_include_index setting (default: true).

Index path resolution:

  1. Entity settings: entity.settings["sitemap_index_path"]
  2. Router Introspection: automatic detection (e.g., /page or /pages)
  3. Per-entity Settings: sitemap_entity_{name}_index_path
  4. Auto-generated fallback: /:entity_name (if sitemap_entities_auto_pattern is true)

Configuration

Settings marked (Admin UI) are exposed to the core Sitemap admin screen via sitemap_settings_schema/0 — on phoenix_kit releases that render source-provided settings schemas, they can be edited there instead of only through PhoenixKit.Settings. On older phoenix_kit releases (or if this package predates the schema being added), every setting below still works exactly as before: console/Settings only.

  • sitemap_entities_auto_pattern - Enable auto URL pattern generation (default: false) (Admin UI)
  • sitemap_entities_include_index - Include entity index pages (default: true) (Admin UI)
  • sitemap_entities_pattern - Global pattern template (e.g., "/:entity_name/:slug") (default: none) (Admin UI)
  • sitemap_entity_{name}_pattern - Per-entity URL pattern override (console/Settings only)
  • sitemap_entity_{name}_index_path - Per-entity index page path override (console/Settings only)

Exclusion

Two levels of opt-out:

  • Per entity: set entity.settings["sitemap_exclude"] = true to keep an entire entity out of the sitemap regardless of its routes or the sitemap_entities_auto_pattern flag. Use this for internal / form entities (e.g. contact_request) whose records default to status "published" and are not meant for public indexing.
  • Per record: set record.metadata["sitemap_exclude"] = true.

Note: only an entity with a genuinely public route or configured URL pattern is eligible in the first place — internal entities with no public URL are excluded automatically. The per-entity flag is the explicit, defensive opt-out.

Sitemap Properties

Records:

  • Priority: 0.8 (high priority for entity content)
  • Change frequency: weekly
  • Category: Entity display name
  • Last modified: Record's date_updated timestamp

Index pages:

  • Priority: 0.7
  • Change frequency: daily
  • Category: Entity display name
  • Last modified: Entity's updated_at timestamp

Summary

Functions

Returns the admin-UI settings schema for this source, so entities-specific sitemap settings can be edited from the core Sitemap admin screen instead of only via PhoenixKit.Settings from the console/IEx.

Returns per-entity-type sub-sitemaps. Each entity type gets its own sitemap file.

Functions

sitemap_settings_schema()

@spec sitemap_settings_schema() :: [
  %{
    key: String.t(),
    type: :boolean | :string | :integer,
    label: String.t(),
    help: String.t() | nil,
    default: term()
  }
]

Returns the admin-UI settings schema for this source, so entities-specific sitemap settings can be edited from the core Sitemap admin screen instead of only via PhoenixKit.Settings from the console/IEx.

Optional callback: the core Sitemap admin only calls this when function_exported?(__MODULE__, :sitemap_settings_schema, 0) is true, so this ships safely against phoenix_kit releases that predate schema-based settings rendering — they simply never call it, and every setting below keeps working exactly as it does today (console/Settings only).

Per-entity overrides (sitemap_entity_{name}_pattern, sitemap_entity_{name}_index_path) are intentionally NOT included here: they're keyed by entity name rather than being a fixed set, so they remain console/Settings-only regardless of admin-UI schema support.

@impl true is safe: sitemap_settings_schema/0 is declared as an @optional_callbacks entry on the Source behaviour in the pinned phoenix_kit (~> 1.7), and the core admin still gates the call behind function_exported?/3, so nothing invokes it on releases that predate the schema-rendering UI.

sub_sitemaps(opts)

@spec sub_sitemaps(keyword()) ::
  [{String.t(), [PhoenixKit.Modules.Sitemap.UrlEntry.t()]}] | nil

Returns per-entity-type sub-sitemaps. Each entity type gets its own sitemap file.