This command-line program generates an XML sitemap from a collection of files.
Several similar programs exist, including one written in Python 2 by Google and another one written in JavaScript by @zerodevx. This one is written in Rust for greater portability: it should work on any platform supported by Rust (except platforms that lack std
).
To build this program:
- Install Rust and Cargo.
- Get a copy of this source code tree.
- Run
cargo build --release
. Cargo will download and compile the libraries thatsitemap-from-files
needs, then buildsitemap-from-files
itself. The--release
option turns on optimizations.
Once you've done this, you'll find a built executable named sitemap-from-files
in the folder target/release
. Feel free to move it wherever is convenient (such as /usr/local/bin
).
To use this program, first you need to write a configuration file. It looks like this:
root_dir = "path/to/site"
root_url = "https://www.example.com/"
sitemap_path = "path/to/site/sitemap.xml"
[[rule]]
match = '\.html$'
include = true
[[rule]]
match = '(^|/)index\.html$'
replace = '$1'
[[rule]]
match = '^secret/'
include = false
See Configuration.md
for an explanation of what goes into a configuration file.
Once the configuration file is written, simply run sitemap-from-files path/to/config.toml
to generate a sitemap.