mirror of
https://github.com/rust-lang/mdBook
synced 2024-12-13 14:22:35 +00:00
add first_chapter function
This commit is contained in:
parent
8357811d96
commit
5d65967448
1 changed files with 14 additions and 0 deletions
14
src/main.rs
14
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<P: AsRef<OsStr>>(path: P) {
|
||||
info!("Opening web browser");
|
||||
if let Err(e) = opener::open(path) {
|
||||
|
|
Loading…
Reference in a new issue