actix-sitemaps-rs

Crates.ioactix-sitemaps-rs
lib.rsactix-sitemaps-rs
version0.1.0
sourcesrc
created_at2024-02-23 19:04:44.229363
updated_at2024-02-23 19:04:44.229363
descriptionAdd a static sitemap to your actix-web app.
homepage
repositoryhttps://github.com/shadawck/actix-sitemap-rs
max_upload_size
id1150910
size10,686
Shadawck (shadawck)

documentation

README

actix-sitemap-rs

Add a static sitemap to your actix-web app.

Add to your project

cargo add actix-sitemap-rs

Use

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
}
Commit count: 0

cargo fmt