pub struct Sitemap { /* private fields */ }Expand description
/sitemap.xml: the pages search engines should crawl.
Answer it from a route (it is a response: application/xml). One
sitemap holds at most 50,000 URLs (and 50 MB); split larger sites.
§Examples
use ocre::seo::{Sitemap, SitemapUrl};
let mut sitemap = Sitemap::new();
sitemap.add(SitemapUrl {
loc: "https://example.com/en/pricing".into(),
lastmod: Some("2026-10-01".into()),
alternates: vec![
("en".into(), "https://example.com/en/pricing".into()),
("fr".into(), "https://example.com/fr/pricing".into()),
],
});
let xml = sitemap.to_xml();
assert!(xml.contains("<url><loc>https://example.com/en/pricing</loc><lastmod>2026-10-01</lastmod>"));
assert!(xml.contains("<xhtml:link rel=\"alternate\" hreflang=\"fr\" href=\"https://example.com/fr/pricing\"/>"));Implementations§
Source§impl Sitemap
impl Sitemap
Sourcepub fn add(&mut self, url: SitemapUrl) -> &mut Self
pub fn add(&mut self, url: SitemapUrl) -> &mut Self
Adds a page.
Sourcepub fn add_localized(
&mut self,
urls: &[(&str, &str)],
lastmod: Option<&str>,
) -> &mut Self
pub fn add_localized( &mut self, urls: &[(&str, &str)], lastmod: Option<&str>, ) -> &mut Self
Adds a page in every language: urls is (hreflang, absolute URL)
for each locale, the first being the default (also x-default).
Each version is listed, with all the others as alternates, as
search engines expect.
§Examples
let mut sitemap = ocre::seo::Sitemap::new();
sitemap.add_localized(&[("en", "https://ex.com/en"), ("fr", "https://ex.com/fr")], None);
let xml = sitemap.to_xml();
assert_eq!(xml.matches("<url>").count(), 2);
assert_eq!(xml.matches("hreflang=\"x-default\" href=\"https://ex.com/en\"").count(), 2);Trait Implementations§
impl Eq for Sitemap
impl StructuralPartialEq for Sitemap
Auto Trait Implementations§
impl Freeze for Sitemap
impl RefUnwindSafe for Sitemap
impl Send for Sitemap
impl Sync for Sitemap
impl Unpin for Sitemap
impl UnsafeUnpin for Sitemap
impl UnwindSafe for Sitemap
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Checks if this value is equivalent to the given key. Read more
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.§impl<T, S> Handler<IntoResponseHandler, S> for T
impl<T, S> Handler<IntoResponseHandler, S> for T
§fn call(
self,
_req: Request<Body>,
_state: S,
) -> <T as Handler<IntoResponseHandler, S>>::Future
fn call( self, _req: Request<Body>, _state: S, ) -> <T as Handler<IntoResponseHandler, S>>::Future
Call the handler with the given request.
§fn layer<L>(self, layer: L) -> Layered<L, Self, T, S>where
L: Layer<HandlerService<Self, T, S>> + Clone,
<L as Layer<HandlerService<Self, T, S>>>::Service: Service<Request<Body>>,
fn layer<L>(self, layer: L) -> Layered<L, Self, T, S>where
L: Layer<HandlerService<Self, T, S>> + Clone,
<L as Layer<HandlerService<Self, T, S>>>::Service: Service<Request<Body>>,
Apply a [
tower::Layer] to the handler. Read more§fn with_state(self, state: S) -> HandlerService<Self, T, S>
fn with_state(self, state: S) -> HandlerService<Self, T, S>
Convert the handler into a [
Service] by providing the state§impl<H, T> HandlerWithoutStateExt<T> for Hwhere
H: Handler<T, ()>,
impl<H, T> HandlerWithoutStateExt<T> for Hwhere
H: Handler<T, ()>,
§fn into_service(self) -> HandlerService<H, T, ()>
fn into_service(self) -> HandlerService<H, T, ()>
Convert the handler into a [
Service] and no state.§fn into_make_service(self) -> IntoMakeService<HandlerService<H, T, ()>>
fn into_make_service(self) -> IntoMakeService<HandlerService<H, T, ()>>
Convert the handler into a
MakeService and no state. Read more