linkmarks_core/
canonical_config.rs1use std::collections::HashMap;
3
4pub const ALWAYS_FUNCTIONAL: &[&str] = &[
6 "id", "page", "q", "query", "search", "lang", "locale", "sort", "order", "limit", "offset",
7 "cursor", "tab", "filter",
8];
9
10#[derive(Debug, Clone, Default)]
11pub struct CanonicalConfig {
13 pub domains: HashMap<String, DomainRules>,
15}
16
17#[derive(Debug, Clone, Default)]
18pub struct DomainRules {
20 pub preserve_params: Vec<String>,
22}
23
24impl CanonicalConfig {
25 pub fn is_preserved(&self, host: &str, param_lc: &str) -> bool {
27 if ALWAYS_FUNCTIONAL.contains(¶m_lc) {
28 return true;
29 }
30 self.domains
31 .get(host)
32 .is_some_and(|r| r.preserve_params.iter().any(|p| p == param_lc))
33 }
34
35 pub fn default_rules() -> Self {
37 Self::default()
38 }
39}