diff --git a/src/main.rs b/src/main.rs index 35562e64..f993d475 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,7 +9,10 @@ use clap::{App, AppSettings, Arg, ArgMatches}; use clap_complete::Shell; use env_logger::Builder; use log::LevelFilter; +use mdbook::book::Chapter; use mdbook::utils; +use mdbook::BookItem; +use mdbook::MDBook; use std::env; use std::ffi::OsStr; use std::io::Write; @@ -137,6 +140,17 @@ fn get_book_dir(args: &ArgMatches) -> PathBuf { } } +// Return the first displayable chapter of the given book, or None if no displayable +// chapter is found (i.e. only drafts). +fn first_chapter(book: &MDBook) -> Option<&PathBuf> { + book.iter().find_map(|item| match item { + BookItem::Chapter(Chapter { + path: Some(path), .. + }) => Some(path), + _ => None, + }) +} + fn open>(path: P) { info!("Opening web browser"); if let Err(e) = opener::open(path) {