use std::collections::HashMap;
pub const ALWAYS_FUNCTIONAL: &[&str] = &[
"id", "page", "q", "query", "search", "lang", "locale", "sort", "order", "limit", "offset",
"cursor", "tab", "filter",
];
#[derive(Debug, Clone, Default)]
pub struct CanonicalConfig {
pub domains: HashMap<String, DomainRules>,
}
#[derive(Debug, Clone, Default)]
pub struct DomainRules {
pub preserve_params: Vec<String>,
}
impl CanonicalConfig {
pub fn is_preserved(&self, host: &str, param_lc: &str) -> bool {
if ALWAYS_FUNCTIONAL.contains(¶m_lc) {
return true;
}
self.domains
.get(host)
.is_some_and(|r| r.preserve_params.iter().any(|p| p == param_lc))
}
pub fn default_rules() -> Self {
Self::default()
}
}