laraindexnow 0.1.2

IndexNow for Laravel Rust: tell Bing, Yandex and other search engines a URL changed, the moment it changes.
Documentation
use laravel::config::Section;

/// How submissions leave the application.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum Driver {
    /// Talk to the endpoint.
    #[default]
    Http,
    /// Go through the whole pipeline and drop the request at the last step.
    Null,
}

/// Where the outcome of every submission is written.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum LogMode {
    /// Discard it.
    #[default]
    Null,
    /// Write it through `tracing`.
    Log,
}

/// The queue the buffer and its flush job use.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct QueueSettings {
    /// Buffer and queue, or send inline.
    pub enabled: bool,
    /// The queue connection, or the default one.
    pub connection: Option<String>,
    /// The queue name, or the connection's default.
    pub queue: Option<String>,
}

impl Default for QueueSettings {
    fn default() -> Self {
        Self {
            enabled: true,
            connection: None,
            queue: None,
        }
    }
}

/// The cache backed buffer model events push URLs into.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct BufferSettings {
    /// The cache store, or the default one.
    pub store: Option<String>,
    /// The cache key the buffer lives under.
    pub key: String,
    /// Seconds the buffer waits before it is flushed.
    pub delay: u64,
    /// How many URLs the buffer holds before it flushes early.
    pub max_urls: usize,
}

impl Default for BufferSettings {
    fn default() -> Self {
        Self {
            store: None,
            key: "indexnow:buffer".to_owned(),
            delay: 60,
            max_urls: 10_000,
        }
    }
}

/// The window in which the same URL is not submitted twice.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct DedupeSettings {
    /// Whether the window applies at all.
    pub enabled: bool,
    /// Its length in seconds.
    pub ttl: u64,
    /// The prefix of the cache keys.
    pub prefix: String,
}

impl Default for DedupeSettings {
    fn default() -> Self {
        Self {
            enabled: true,
            ttl: 3600,
            prefix: "indexnow:sent:".to_owned(),
        }
    }
}

/// What `indexnow:due` looks back over.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct DueSettings {
    /// Hours to look back, overridden by `--hours`.
    pub hours: u64,
}

impl Default for DueSettings {
    fn default() -> Self {
        Self { hours: 25 }
    }
}

/// Where `indexnow:due` finds pages besides the ones you register in code.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct SourceSettings {
    /// Read the models tracked with `publishes_at`.
    pub models: bool,
    /// Sitemaps (or sitemap indexes) to read.
    pub sitemaps: Vec<String>,
}

impl Default for SourceSettings {
    fn default() -> Self {
        Self {
            models: true,
            sitemaps: Vec::new(),
        }
    }
}

/// The package's configuration, the equivalent of `config/indexnow.php`.
///
/// Only `enabled` reads the environment, through `INDEXNOW_ENABLED`: it is an operational kill
/// switch, not configuration. Everything else describes how the application works and is set in
/// `src/app.rs` with `with_config`.
#[derive(Debug, Clone, Section)]
pub struct IndexNowConfig {
    /// Master switch. When off, nothing leaves the application.
    #[env("INDEXNOW_ENABLED", default = true)]
    pub enabled: bool,

    /// Submissions only happen in these environments. Empty means everywhere.
    #[section(default = vec!["production".to_owned()])]
    pub environments: Vec<String>,

    /// The shared endpoint, which propagates to every participating search engine.
    #[section(default = "https://api.indexnow.org/indexnow")]
    pub endpoint: String,

    /// Seconds to wait for the endpoint.
    #[section(default = 10)]
    pub timeout: u64,

    /// `Http` talks to the endpoint, `Null` drops the request at the last step.
    pub driver: Driver,

    /// The key of single domain applications, 8 to 128 letters, numbers and dashes.
    pub key: Option<String>,

    /// One key per host, for applications serving several domains.
    pub keys: std::collections::BTreeMap<String, String>,

    /// Set it only when the key file is hosted somewhere other than the root of the domain.
    pub key_location: Option<String>,

    /// Serve `/{key}.txt` from the application.
    #[section(default = true)]
    pub serve_key_file: bool,

    /// Allowed hosts. Derived from the keys, or from `APP_URL`, when empty.
    pub hosts: Vec<String>,

    /// The queue the buffer is flushed through.
    pub queue: QueueSettings,

    /// The buffer model events push URLs into.
    pub buffer: BufferSettings,

    /// The deduplication window.
    pub dedupe: DedupeSettings,

    /// Changes limited to these attributes are not a content change.
    #[section(default = ["remember_token", "views", "view_count", "last_seen_at"].map(str::to_owned).to_vec())]
    pub ignored_attributes: Vec<String>,

    /// Where the outcome of every submission goes.
    pub log: LogMode,

    /// What `indexnow:due` looks back over.
    pub due: DueSettings,

    /// Where `indexnow:due` finds pages.
    pub sources: SourceSettings,
}