https://github.com/goddtriffin/sitemap-rs
A Rust library to generate URL, Index, Image, Video, and News sitemaps.
https://github.com/goddtriffin/sitemap-rs
bing-webmaster google-search-console rust seo seo-optimization seo-tools sitemap sitemap-generator xml
Last synced: 2 months ago
JSON representation
A Rust library to generate URL, Index, Image, Video, and News sitemaps.
- Host: GitHub
- URL: https://github.com/goddtriffin/sitemap-rs
- Owner: goddtriffin
- License: mit
- Created: 2022-09-02T19:20:59.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2025-08-30T19:24:59.000Z (10 months ago)
- Last Synced: 2025-12-13T22:35:20.578Z (6 months ago)
- Topics: bing-webmaster, google-search-console, rust, seo, seo-optimization, seo-tools, sitemap, sitemap-generator, xml
- Language: Rust
- Homepage: https://docs.rs/sitemap-rs
- Size: 110 KB
- Stars: 29
- Watchers: 1
- Forks: 6
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
# sitemap-rs
[](https://crates.io/crates/sitemap-rs)
[](https://docs.rs/sitemap-rs)
A Rust library to generate URL, Index, Image, Video, and News sitemaps.
## Features
### Generates sitemaps
- [URL sitemaps](https://www.sitemaps.org/protocol.html)
- [Index sitemaps](https://www.sitemaps.org/protocol.html)
- [Image sitemaps](https://developers.google.com/search/docs/advanced/sitemaps/image-sitemaps)
- [Video sitemaps](https://developers.google.com/search/docs/advanced/sitemaps/video-sitemaps)
- [News sitemaps](https://developers.google.com/search/docs/advanced/sitemaps/news-sitemap)
### Validates sitemap data
There are a bunch of restrictions as to what data your sitemaps can hold. This
library surfaces these validation issues at struct instantiation time. Now you
don't have to wait for
[Google Search Console](https://search.google.com/search-console/about) or
[Bing Webmaster Tools](https://www.bing.com/webmasters/tools) to alert you of
sitemap issues before you can fix data problems.
#### Validations
- URL Sitemap
- `LocationTooLong`
- A `` must be less than `2,048` characters.
- `TooManyUrls`
- Can only contain as many as `50,000` ``.
- `TooMuchNews`
- Can only contain as many as `1,000` ``.
- `PriorityTooLow` and `PriorityTooHigh`
- A `` must be between `0.0` and `1.0` (inclusive).
- `TooManyImages`
- Can only contain as many as `1,000` ``.
- Index Sitemap
- `TooManySitemaps`
- Can only contain as many as `50,000` ``.
- Video Sitemap
- `DescriptionTooLong`
- A `` must be no longer than `2048` characters.
- `DurationTooShort` and `DurationTooLong`
- A `` must be between `1` and `28,800` seconds (inclusive).
- `RatingTooLow` and `RatingTooHigh`
- A `` must be between `0.0` and `5.0` (inclusive).
- `UploaderNameTooLong`
- An ``'s `` must be no longer than `255` characters.
- `TooManyTags`
- Must contain no more than `32` ``.
## Restrictions
This library **cannot** parse sitemaps of any kind (yet! - pull requests
welcome! See Feature Requests section below).
## Examples
### URL Sitemap
`cargo run --example generate_url_sitemap`
```xml
https://www.toddgriffin.me/
1998-01-15T04:20:00+00:00
monthly
0.69
```
### Index Sitemap
`cargo run --example generate_index_sitemap`
```xml
https://www.toddgriffin.me/sitemap1.xml.gz
1998-01-15T04:20:00+00:00
https://www.toddgriffin.me/sitemap2.xml.gz
2000-01-31T04:20:00+00:00
```
### Image Sitemap
`cargo run --example generate_image_sitemap`
```xml
https://www.toddgriffin.me/sample1.html
https://www.toddgriffin.me/image.jpg
https://www.toddgriffin.me/photo.jpg
https://www.toddgriffin.me/sample2.html
https://www.toddgriffin.me/picture.jpg
```
### Video Sitemap
`cargo run --example generate_video_sitemap`
```xml
https://www.toddgriffin.me/videos/some_video_landing_page.html
https://www.toddgriffin.me/thumbs/123.jpg
Grilling steaks for summer
Alkis shows you how to get perfectly done steaks every time
https://www.toddgriffin.me/video123.mp4
https://www.toddgriffin.me/videoplayer.php?video=123
600
2021-11-05T19:20:30+08:00
4.2
8633
1998-01-15T12:20:00+08:00
yes
CA GB IE US
tv web
yes
GrillyMcGrillserson
no
steak
meat
summer
outdoor
```
### News Sitemap
`cargo run --example generate_news_sitemap`
```xml
https://www.toddgriffin.me/business/article55.html
The Example Times
en
1998-01-15T04:20:00+00:00
Companies A, B in Merger Talks
```
## Alternative libraries
_The `rust-sitemap` and `sitewriter` libraries are by far the best
alternatives._
_This pro/con list is accurate as of the most recent update to this document._
### [rust-sitemap](https://github.com/svmk/rust-sitemap)
#### Pros:
- Supports URL, Index sitemaps
- Supports reading files
- Supports writing files
#### Cons:
- Doesn't support Image, Video, News sitemaps
- Only supports some validations
- Low struct/method documentation
### [sitewriter](https://github.com/edg-l/sitewriter)
#### Pros:
- Supports URL sitemaps
- Supports writing files
- Support builder pattern
- uses [quick-xml](https://github.com/tafia/quick-xml), so it should be quite
fast
- Some struct/method documentation
#### Cons:
- Doesn't support Index, Image, Video, News sitemaps
- Doesn't support reading files
- Zero data validations
### [sitemap-iter](https://github.com/Icelk/sitemap-iter/)
#### Pros:
- Supports URL sitemaps
- Supports reading files
#### Cons:
- Doesn't support Index, Image, Video, News sitemaps
- Doesn't support writing files
- Zero data validations
- Low struct/method documentation
### [rust-sitemap-writer](https://github.com/uiuifree/rust-sitemap-writer)
#### Pros:
- Supports URL sitemaps
- Supports writing files
#### Cons:
- Doesn't support Index, Image, Video, News sitemaps
- Doesn't support reading files
- Zero data validations
- Zero struct/method documentation
### [mdbook-sitemap-generator](https://github.com/rxdn/mdbook-sitemap-generator)
#### Pros:
- Semi-supports URL sitemaps
- Supports writing files
#### Cons:
- Not a general use sitemap library
- Doesn't support every possible tag of URL sitemaps
- Doesn't support Index, Image, Video, News sitemaps
- Doesn't support reading files
- Zero data validations
- Zero struct/method documentation
## Developers
**Project is under active maintenance - even if there are no recent commits!
Please submit an issue / bug request if the library needs updating for any
reason!**
### Philosophy
This library should be fast, efficient, strictly adhere to the Sitemap
specification, and strictly adhere to Google Search Console's best practices.
A feature request will be accepted if it exists in the specification and if it
is a best practice to use it.
For example, here are some deprecated Image Sitemap fields: ``,
``, ``, ``. While the
specification technically describes these fields, Google Search Console's best
practices is to omit them.
> Over the years, we introduced a number of tags and tag attributes for Google
> sitemap extensions, specifically the Image and Video extensions.
>
> Most of these tags were added to allow site owners to deliver data more easily
> to Search. Upon evaluating the value of the Google sitemap extension tags, we
> decided to officially deprecate some tags and attributes, and remove them from
> our documentation. The deprecated tags will have no effect on indexing and
> search features after August 6, 2022.
>
> If you are a sitemap plugin developer or manage your own sitemaps, there's no
> immediate action required; you can leave these tags and attributes in place
> without drawbacks. In the future, Search Console may show warnings once these
> updates are included in the next schema versions of the Image and Video
> extensions.
Source:
https://developers.google.com/search/docs/crawling-indexing/sitemaps/image-sitemaps
Any contribution which doesn't follow this philosophy will unfortunately be
closed.
On the flip side, if this library has not implemented any feature of the Sitemap
spec - it must be implemented!
### Specification
- https://www.sitemaps.org/protocol.html
- https://developers.google.com/search/docs/crawling-indexing/sitemaps/build-sitemap#xml
- https://developers.google.com/search/docs/specialty/international/localized-versions#sitemap
- https://developers.google.com/search/docs/specialty/international/localized-versions#all-method-guidelines
- https://developers.google.com/search/docs/specialty/international/localized-versions#xdefault
### Feature Requests
These are extremely high priority! Very open to contributions!
- `Replace xml-builder dependency with quick-xml (faster + enable reading sitemaps)`: https://github.com/goddtriffin/sitemap-rs/issues/14
- `Add strict validations: ISO 3166 Country Code, ISO 639 Part 1 Language Code, ISO 15924 Language Script Variations`: https://github.com/goddtriffin/sitemap-rs/issues/15
### Commands
- `make lint`
- `make test`
- `make fix`
## Credits
Made by [Todd Everett Griffin](https://www.toddgriffin.me/).