improve docs

This commit is contained in:
Edgar 2020-11-22 16:07:45 +01:00
parent 3e402a8cfd
commit d43bc84861
No known key found for this signature in database
GPG key ID: 8731E6C0166EAA85
2 changed files with 54 additions and 2 deletions

View file

@ -1,6 +1,6 @@
[package] [package]
name = "sitewriter" name = "sitewriter"
version = "0.1.0" version = "0.1.1"
authors = ["Edgar L. <contact@edgarluque.com>"] authors = ["Edgar L. <contact@edgarluque.com>"]
edition = "2018" edition = "2018"
description = "A sitemap writing library." description = "A sitemap writing library."

View file

@ -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")] #[cfg(feature = "chrono")]
use chrono::{DateTime, Utc, SecondsFormat}; use chrono::{DateTime, Utc, SecondsFormat};
use quick_xml::{ use quick_xml::{
events::{BytesDecl, BytesEnd, BytesStart, BytesText, Event}, events::{BytesDecl, BytesEnd, BytesStart, BytesText, Event},
Writer, Writer,
}; };
use std::fmt::Display; use std::fmt::Display;
use std::io::Cursor; use std::io::Cursor;
use std::borrow::Cow; use std::borrow::Cow;
@ -98,7 +150,7 @@ impl<'a> Sitemap<'a> {
/// Generates the sitemap using the provided writer. /// 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<T>(&self, inner_writer: T) -> T pub fn generate<T>(&self, inner_writer: T) -> T
where where
T: std::io::Write, T: std::io::Write,