diff --git a/src/cmd/watch.rs b/src/cmd/watch.rs index 78ae1968..2effd29f 100644 --- a/src/cmd/watch.rs +++ b/src/cmd/watch.rs @@ -1,3 +1,4 @@ +use crate::first_chapter; use crate::{get_book_dir, open}; use clap::{arg, App, Arg, ArgMatches}; use mdbook::errors::Result; @@ -45,7 +46,12 @@ pub fn execute(args: &ArgMatches) -> Result<()> { if args.is_present("open") { book.build()?; - open(book.build_dir_for("html").join("index.html")); + match first_chapter(&book) + .map(|path| book.build_dir_for("html").join(path).with_extension("html")) + { + Some(path) if Path::new(&path).exists() => open(path), + _ => warn!("No chapter available to open"), + } } trigger_on_change(&book, |paths, book_dir| {