use laravel::config::Section;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum Driver {
#[default]
Http,
Null,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum LogMode {
#[default]
Null,
Log,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct QueueSettings {
pub enabled: bool,
pub connection: Option<String>,
pub queue: Option<String>,
}
impl Default for QueueSettings {
fn default() -> Self {
Self {
enabled: true,
connection: None,
queue: None,
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct BufferSettings {
pub store: Option<String>,
pub key: String,
pub delay: u64,
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,
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct DedupeSettings {
pub enabled: bool,
pub ttl: u64,
pub prefix: String,
}
impl Default for DedupeSettings {
fn default() -> Self {
Self {
enabled: true,
ttl: 3600,
prefix: "indexnow:sent:".to_owned(),
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct DueSettings {
pub hours: u64,
}
impl Default for DueSettings {
fn default() -> Self {
Self { hours: 25 }
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct SourceSettings {
pub models: bool,
pub sitemaps: Vec<String>,
}
impl Default for SourceSettings {
fn default() -> Self {
Self {
models: true,
sitemaps: Vec::new(),
}
}
}
#[derive(Debug, Clone, Section)]
pub struct IndexNowConfig {
#[env("INDEXNOW_ENABLED", default = true)]
pub enabled: bool,
#[section(default = vec!["production".to_owned()])]
pub environments: Vec<String>,
#[section(default = "https://api.indexnow.org/indexnow")]
pub endpoint: String,
#[section(default = 10)]
pub timeout: u64,
pub driver: Driver,
pub key: Option<String>,
pub keys: std::collections::BTreeMap<String, String>,
pub key_location: Option<String>,
#[section(default = true)]
pub serve_key_file: bool,
pub hosts: Vec<String>,
pub queue: QueueSettings,
pub buffer: BufferSettings,
pub dedupe: DedupeSettings,
#[section(default = ["remember_token", "views", "view_count", "last_seen_at"].map(str::to_owned).to_vec())]
pub ignored_attributes: Vec<String>,
pub log: LogMode,
pub due: DueSettings,
pub sources: SourceSettings,
}