mirror of
https://github.com/edg-l/sitewriter.git
synced 2024-11-09 17:48:24 +00:00
improve docs
This commit is contained in:
parent
3e402a8cfd
commit
d43bc84861
|
@ -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."
|
||||||
|
|
54
src/lib.rs
54
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")]
|
#[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,
|
||||||
|
|
Loading…
Reference in a new issue