call find_chapter when opening browser

This commit is contained in:
josh rotenberg 2022-05-11 13:14:38 -07:00
parent 8b49600673
commit c74c682939
1 changed files with 6 additions and 4 deletions

View File

@ -1,6 +1,6 @@
#[cfg(feature = "watch")]
use super::watch;
use crate::{get_book_dir, open};
use crate::{first_chapter, get_book_dir, open};
use clap::{arg, App, Arg, ArgMatches};
use futures_util::sink::SinkExt;
use futures_util::StreamExt;
@ -102,10 +102,12 @@ pub fn execute(args: &ArgMatches) -> Result<()> {
serve(build_dir, sockaddr, reload_tx, &file_404);
});
let serving_url = format!("http://{}", address);
info!("Serving on: {}", serving_url);
if open_browser {
let serving_url = match first_chapter(&book).map(|path| path.with_extension("html")) {
Some(path) => format!("http://{}/{}", address, path.display()),
_ => format!("http://{}", address),
};
info!("Serving on: {}", serving_url);
open(serving_url);
}