laraindexnow 0.1.0

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

use crate::record::Record;

/// The rules of a tracked model, for registrations too large to read as a chain.
///
/// It is the equivalent of the PHP package's `Policy` class. Only [`url`](Policy::url) is
/// required.
///
/// ```ignore
/// struct PostIndexNow;
///
/// impl Policy<Post> for PostIndexNow {
///     fn url(&self, post: &Post) -> Option<String> {
///         Some(format!("https://example.com/blog/{}", post.slug))
///     }
///
///     fn when(&self, record: &Record) -> bool {
///         record.text("status") == Some("published")
///     }
/// }
///
/// indexnow::track::<Post>().policy(PostIndexNow)
/// ```
pub trait Policy<M: Model>: Send + Sync + 'static {
    /// The canonical URL of the record. Return `None` and it is never submitted.
    fn url(&self, model: &M) -> Option<String>;

    /// The address the record had before a write, when it can be read from the record's state.
    /// Used to announce the old URL of a record whose slug changed.
    fn previous_url(&self, _before: &Record) -> Option<String> {
        None
    }

    /// Whether the record belongs in the index. Asked about the state before and after a write.
    fn when(&self, _record: &Record) -> bool {
        true
    }

    /// Attributes whose change is not a content change.
    fn ignoring(&self) -> Vec<String> {
        Vec::new()
    }

    /// Other URLs a write left out of date.
    fn affects(&self, _model: &M) -> Vec<String> {
        Vec::new()
    }
}