feat: SitemapPlugin path and sitemap index options

BE
2d ago
+313-6

The SitemapPlugin always writes public/sitemap.xml. A site served by more than one backend, say a Reflex app for most pages and a CMS for a blog under the same domain, usually publishes a sitemap per part and a sitemap index at /sitemap.xml that lists them. Today that means letting the plugin write sitemap.xml and moving the file in a custom plugin after the build, which every other plugin that modifies the sitemap has to know about.

This PR adds three options:

rx.plugins.SitemapPlugin(
    path="sitemap-app.xml",
    index_path="sitemap.xml",
    index_sitemaps=["https://www.example.com/sitemap-blog.xml"],
)
  • path (default sitemap.xml) is where the sitemap is written below the frontend's public root, which is also its URL path below frontend_path.
  • index_path, if set, adds a sitemap index there, listing the app's sitemap (its absolute URL, frontend_url plus frontend_path plus path) followed by index_sitemaps, which take absolute URLs or paths resolved against deploy_url like a page's loc.
  • SitemapPlugin.file_path names the generated file, so a plugin that adds to the sitemap through add_modify_task (e.g. hreflang alternates) can find it instead of assuming Constants.FILE_PATH.

Paths are normalized without leading or trailing slashes; an empty path, or an index_path naming the sitemap itself, raises a ValueError. With no options the output is unchanged. Docs in docs/api-reference/plugins.md.