From d43bc84861eea0be7a8868c9ba00a1222663bca3 Mon Sep 17 00:00:00 2001 From: Edgar Date: Sun, 22 Nov 2020 16:07:45 +0100 Subject: [PATCH] improve docs --- Cargo.toml | 2 +- src/lib.rs | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 54 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index a84080f..d4306b8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "sitewriter" -version = "0.1.0" +version = "0.1.1" authors = ["Edgar L. "] edition = "2018" description = "A sitemap writing library." diff --git a/src/lib.rs b/src/lib.rs index 202fb6a..b10b41c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,9 +1,61 @@ +//! ## A rust library to generate sitemaps. +//! +//! It uses the [quick-xml](https://github.com/tafia/quick-xml) so it should be fast. +//! +//! To handle the [`Url::lastmod`] tag it uses [chrono](https://docs.rs/chrono/) but it can be disabled with `default-features = false`. +//! +//! ## Example +//! +//! ```rust +//! use chrono::prelude::*; +//! use sitewriter::*; +//! +//! fn main() { +//! let mut sitemap = Sitemap::new(); +//! sitemap.urls.push(Url::new("https://edgarluque.com/projects")); +//! +//! sitemap.urls.push(Url { +//! loc: "https://edgarluque.com/", +//! changefreq: Some(ChangeFreq::Daily), +//! priority: Some(1.0), +//! lastmod: Some(Utc::now()), +//! }); +//! +//! sitemap.urls.push(Url { +//! loc: "https://edgarluque.com/blog", +//! changefreq: Some(ChangeFreq::Weekly), +//! priority: Some(0.8), +//! lastmod: Some(Utc::now()), +//! }); +//! +//! sitemap.urls.push(Url { +//! loc: "https://edgarluque.com/blog/sitewriter", +//! changefreq: Some(ChangeFreq::Never), +//! priority: Some(0.5), +//! lastmod: Some(Utc.ymd(2020, 11, 22).and_hms(15, 10, 15)), +//! }); +//! +//! sitemap.urls.push(Url { +//! loc: "https://edgarluque.com/blog/some-future-post", +//! changefreq: Some(ChangeFreq::Never), +//! priority: Some(0.5), +//! lastmod: Some(Utc.from_utc_datetime(&Local.ymd(2020, 12, 5).and_hms(12, 30, 0).naive_utc())), +//! }); +//! +//! +//! let result = sitemap.into_str(); +//! println!("{}", result); +//! } +//! ``` + #[cfg(feature = "chrono")] use chrono::{DateTime, Utc, SecondsFormat}; + use quick_xml::{ events::{BytesDecl, BytesEnd, BytesStart, BytesText, Event}, Writer, }; + use std::fmt::Display; use std::io::Cursor; use std::borrow::Cow; @@ -98,7 +150,7 @@ impl<'a> Sitemap<'a> { /// Generates the sitemap using the provided writer. /// - /// It's recommended to use [`into_bytes`] or [`into_str`] + /// It's recommended to use [`Sitemap::into_bytes()`] or [`Sitemap::into_str()`] pub fn generate(&self, inner_writer: T) -> T where T: std::io::Write,