laraindexnow 0.1.2

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

/// A page that became public or changed, with the moment it did.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Page {
    /// The absolute URL.
    pub url: String,
    /// When it changed. Never in the future.
    pub changed_at: Timestamp,
}

impl Page {
    /// A page changed at a given moment.
    pub fn new(url: impl Into<String>, changed_at: Timestamp) -> Self {
        Self {
            url: url.into(),
            changed_at,
        }
    }

    /// The lowercase host of the URL, or an empty string when the URL has none.
    pub fn host(&self) -> String {
        url::Url::parse(&self.url)
            .ok()
            .and_then(|url| url.host_str().map(str::to_lowercase))
            .unwrap_or_default()
    }
}

/// Where `indexnow:due` finds the pages that changed without an Eloquent-style write.
///
/// A source returns the pages that became public or changed between `since` and now, each with an
/// absolute URL and the date of the change. Never return a date in the future.
#[async_trait]
pub trait Source: Send + Sync {
    /// A name for error messages. Defaults to the type's name.
    fn name(&self) -> String {
        std::any::type_name::<Self>().to_owned()
    }

    /// The pages that became public or changed since `since`.
    async fn changed_since(&self, since: Timestamp) -> laravel::Result<Vec<Page>>;
}