Expand description
File-watching for live rebuild. File-watching module for the static site generator.
Provides a polling-based file watcher that monitors a content directory
for changes and triggers rebuilds when modifications are detected.
Uses only std library types — no external dependencies required.
§Architecture
The watcher tracks file modification times in a HashMap and compares
them on each poll cycle. Three kinds of changes are detected:
- Modified — a file’s
mtimehas advanced since the last snapshot. - Added — a file exists on disk but was not present in the snapshot.
- Removed — a file was in the snapshot but is no longer on disk.
§Example
use std::path::PathBuf;
use std::time::Duration;
use ssg::watch::{FileWatcher, WatchConfig};
let config = WatchConfig::new(
PathBuf::from("content"),
Duration::from_secs(2),
);
let mut watcher = FileWatcher::new(config).expect("failed to create watcher");
// Non-blocking: check once and get changed paths.
let changes = watcher.check_for_changes().expect("check failed");
if !changes.is_empty() {
println!("Changed files: {:?}", changes);
}Structs§
- File
Watcher - A polling-based file watcher that tracks modification times.
- Watch
Config - Configuration for the file watcher.
Enums§
- Change
Kind - Categorises a file change for selective reload.
Constants§
- MAX_
WATCH_ ITERATIONS - Enters a blocking poll loop that invokes
callbackwhenever file changes are detected.
Functions§
- classify_
change - Classifies a changed file path for selective reload.
- watch_
blocking - Polls for file changes in a blocking loop, invoking
callbackwith changed paths.