1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
//! This crate provides a library for writing [`sitemap.xml`](https://www.sitemaps.org/).
//!
//! # Usage
//!
//! This crate is on crates.io and can be used by adding `sitemap-xml-writer` to your dependencies in your project’s Cargo.toml.
//!
//! ```toml
//! [dependencies]
//! sitemap-xml-writer = "0.1.0"
//! ```
//!
//! # Writers
//!
//! - [`SitemapWriter`]: A writer for sitemap file.
//! - [`SitemapIndexWriter`]: A writer for sitemap index file.
//!
//! # Example: Write sitemap file
//!
//! ```rust
//! use sitemap_xml_writer::{Changefreq, SitemapWriter, Url};
//! use std::io::Cursor;
//!
//! # fn main() -> anyhow::Result<()> {
//! let mut writer = SitemapWriter::start(Cursor::new(Vec::new()))?;
//! writer.write(
//! Url::loc("http://www.example.com/")?
//! .lastmod("2005-01-01")?
//! .changefreq("monthly")?
//! .priority("0.8")?,
//! )?;
//! writer.end()?;
//!
//! assert_eq!(
//! String::from_utf8(writer.into_inner().into_inner())?,
//! concat!(
//! r#"<?xml version="1.0" encoding="UTF-8"?>"#,
//! r#"<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">"#,
//! r#"<url>"#,
//! r#"<loc>http://www.example.com/</loc>"#,
//! r#"<lastmod>2005-01-01</lastmod>"#,
//! r#"<changefreq>monthly</changefreq>"#,
//! r#"<priority>0.8</priority>"#,
//! r#"</url>"#,
//! r#"</urlset>"#
//! )
//! );
//! # Ok(())
//! # }
//! ```
//!
//! # Example: Write sitemap index file
//!
//! ```rust
//! use sitemap_xml_writer::{SitemapIndexWriter, Sitemap};
//! use std::io::Cursor;
//!
//! # fn main() -> anyhow::Result<()> {
//! let mut writer = SitemapIndexWriter::start(Cursor::new(Vec::new()))?;
//! writer.write(
//! Sitemap::loc("http://www.example.com/sitemap1.xml.gz")?
//! .lastmod("2004-10-01T18:23:17+00:00")?
//! )?;
//! writer.end()?;
//!
//! assert_eq!(
//! String::from_utf8(writer.into_inner().into_inner())?,
//! concat!(
//! r#"<?xml version="1.0" encoding="UTF-8"?>"#,
//! r#"<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">"#,
//! r#"<sitemap>"#,
//! r#"<loc>http://www.example.com/sitemap1.xml.gz</loc>"#,
//! r#"<lastmod>2004-10-01T18:23:17+00:00</lastmod>"#,
//! r#"</sitemap>"#,
//! r#"</sitemapindex>"#
//! )
//! );
//! # Ok(())
//! # }
//!
mod changefreq;
mod lastmod;
mod loc;
mod priority;
mod sitemap;
mod sitemap_index_writer;
mod sitemap_writer;
mod sitemap_xml_writer;
mod url;
pub use self::changefreq::Changefreq;
pub use self::lastmod::Lastmod;
pub use self::loc::Loc;
pub use self::priority::Priority;
pub use self::sitemap::Sitemap;
pub use self::sitemap_index_writer::SitemapIndexWriter;
pub use self::sitemap_writer::SitemapWriter;
pub use self::url::Url;