-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Description
Problem
Some file systems one might reasonably want to use with mdBook don't support change events (mounted Windows file systems under WSL2 are rather infamous for this). If your book is on such a file system, the watch and serve commands cannot detect changes, making them not very useful.
Proposed Solution
The watch and serve commands could have an option (e.g. --poll) to detect changes by periodically polling the file system.
Implementation
I'm not at all familiar with Rust, but it appears the notify package used by mdBook already has a PollWatcher intended for just this situation. So, mdBook would not have to implement this logic from scratch.
Prior Art
Polling is supported by some popular static site generators; I'm familiar with it from Hugo, but Jekyll apparently has it as well. Hugo requires the user to specify a poll interval, but suggests 700ms as a default. In my experience this strikes a decent balance between responsiveness and resource usage for small sites, but those with more files might warrant a higher value.
Workarounds
The command-line tool fswatch supports polling, with a default interval of 1s. I've gotten it working with mdBook like so (then opening the output files using file:// in the browser):
fswatch -m poll_monitor -o -r src | xargs -I{} mdbook build
This is not quite as ergonomic as a built-in option would be — it deletes and recreates everything in the output directory on every change, which takes a second or two, and if you refresh before it's ready you can get a 404 or missing CSS/fonts.