Crate sitemap_writer

Crate sitemap_writer 

Source
Expand description

§sitemap-writer

A simple and lightweight Rust library for generating XML sitemaps.

§Features

  • Simple API for creating sitemaps
  • Automatic XML escaping for special characters
  • Support for all sitemap properties (loc, lastmod, changefreq, priority)
  • Support for Sitemap Index (for large sites with 50,000+ URLs)
  • Write directly to file or build as String

§Quick Start

use sitemap_writer::{SitemapWriter, SitemapUrl, SitemapChangeFreq};

// Build sitemap as String
let xml = SitemapWriter::build(vec![
    SitemapUrl {
        loc: "https://example.com/".to_string(),
        lastmod: Some("2024-01-01".to_string()),
        changefreq: Some(SitemapChangeFreq::DAILY),
        priority: Some(1.0),
    },
    SitemapUrl::new("https://example.com/about/"),
]);

§Writing to a File

use sitemap_writer::{SitemapWriter, SitemapUrl};

let result = SitemapWriter::make("sitemap.xml", vec![
    SitemapUrl::new("https://example.com/"),
]);
assert!(result.is_ok());

§Sitemap Index

For large sites with more than 50,000 URLs, use Sitemap Index to reference multiple sitemaps:

use sitemap_writer::{SitemapIndexWriter, SitemapIndex};

let xml = SitemapIndexWriter::build(vec![
    SitemapIndex {
        loc: "https://example.com/sitemap1.xml".to_string(),
        lastmod: Some("2024-01-01".to_string()),
    },
    SitemapIndex::new("https://example.com/sitemap2.xml"),
]);

Structs§

SitemapIndex
Represents a single sitemap entry in a sitemap index.
SitemapIndexWriter
A writer for generating XML sitemap index files.
SitemapUrl
Represents a single URL entry in a sitemap.
SitemapWriter
A writer for generating XML sitemaps.

Enums§

SitemapChangeFreq
Indicates how frequently the content at a URL is likely to change.
SitemapError
Errors that can occur when writing a sitemap.