From 29c729fd2323d9ef6022fea881f6ac4d9223f2ef Mon Sep 17 00:00:00 2001 From: josh rotenberg Date: Tue, 10 May 2022 11:17:20 -0700 Subject: [PATCH] call first_chapter --- src/cmd/build.rs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/cmd/build.rs b/src/cmd/build.rs index dacf45cf..c0a28ec0 100644 --- a/src/cmd/build.rs +++ b/src/cmd/build.rs @@ -1,4 +1,4 @@ -use crate::{get_book_dir, open}; +use crate::{first_chapter, get_book_dir, open}; use clap::{arg, App, Arg, ArgMatches}; use mdbook::errors::Result; use mdbook::MDBook; @@ -39,13 +39,15 @@ pub fn execute(args: &ArgMatches) -> Result<()> { if args.is_present("open") { // FIXME: What's the right behaviour if we don't use the HTML renderer? - let path = book.build_dir_for("html").join("index.html"); - if !Path::new(&path).exists() { - error!("Need a more descriptive error here: {:?}", path); - std::process::exit(1); + 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), + _ => { + error!("No chapter available to open"); + std::process::exit(1) + } } - - open(book.build_dir_for("html").join("index.html")); } Ok(())