Crates.io | actix-sitemaps-rs |
lib.rs | actix-sitemaps-rs |
version | 0.1.0 |
source | src |
created_at | 2024-02-23 19:04:44.229363 |
updated_at | 2024-02-23 19:04:44.229363 |
description | Add a static sitemap to your actix-web app. |
homepage | |
repository | https://github.com/shadawck/actix-sitemap-rs |
max_upload_size | |
id | 1150910 |
size | 10,686 |
Add a static sitemap to your actix-web app.
cargo add actix-sitemap-rs
use actix_sitemaps_rs::{serve_sitemap, ShowErrorMessageStrategy, SitemapBuilder};
use actix_web::{web::Data, App, HttpServer};
#[actix_web::main]
async fn main() -> std::io::Result<()> {
// Sitemap will be available at : http://127.0.0.1:8080/.well-known/sitemaps.xml
let sitemap = SitemapBuilder::default()
.static_file("./tests/sitemaps.xml".to_string())
.web_directory(".well-known".to_string())
.web_filename("sitemaps.xml".to_string())
.not_found_strategy(ShowErrorMessageStrategy) // or RedirectToRootStrategy
.build();
HttpServer::new(move || {
App::new()
.app_data(Data::new(sitemap.clone()))
.service(serve_sitemap) // Declare Sitemap as a service
})
.bind(("127.0.0.1", 8080))?
.run()
.await
}