Skip to main content

sova_meta/
sitemap_config.rs

1//! Shared sitemap config visible to Robots (`Sitemap:` line).
2
3/// Published by [`crate::Sitemap`] so [`crate::Robots`] can emit `Sitemap:`.
4#[derive(Debug, Clone)]
5pub struct SitemapConfig {
6    pub public_url: Option<String>,
7    /// Mount path, e.g. `/sitemap.xml`.
8    pub path: String,
9}
10
11impl SitemapConfig {
12    pub fn sitemap_url(&self) -> Option<String> {
13        let base = self.public_url.as_ref()?;
14        let base = base.trim_end_matches('/');
15        let path = if self.path.starts_with('/') {
16            self.path.clone()
17        } else {
18            format!("/{}", self.path)
19        };
20        Some(format!("{base}{path}"))
21    }
22}
23
24impl Default for SitemapConfig {
25    fn default() -> Self {
26        Self {
27            public_url: None,
28            path: "/sitemap.xml".into(),
29        }
30    }
31}