diff --git a/src/commands/server.rs b/src/commands/server.rs index 90b6e4b..2031ea9 100644 --- a/src/commands/server.rs +++ b/src/commands/server.rs @@ -19,19 +19,14 @@ pub fn serve_site( let project_directory = project.root_dir(); // Check if build directory is available. - let build_directory = project_directory.clone().join("build"); + let build_directory = project.build_dir(); if !build_directory.exists() || !build_directory.is_dir() { caution_message("This project needs a build first!"); header_message("Attempting to build the site..."); build_site(project_directory.clone(), true)?; } - let watched_folder = project_directory - .canonicalize() - .unwrap_or_default() - .to_str() - .unwrap_or_default() - .to_string(); + let watched_folder = project_directory.to_str().unwrap_or_default().to_string(); spawn(move || watch(watched_folder)); success_message("Found a built site to serve!"); @@ -85,7 +80,7 @@ fn watch(watch_path: String) -> notify::Result<()> { let project = Project::new(&watch_path); setup_watchers(&mut watcher, &project)?; - let build_dir = project_root_dir.join("build"); + let build_dir = project.build_dir(); loop { match rx.recv() { diff --git a/src/lib.rs b/src/lib.rs index 7d1191d..259fc30 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -26,6 +26,9 @@ impl Project { pub fn root_dir(&self) -> PathBuf { Path::new(&self.root).to_path_buf() } + pub fn build_dir(&self) -> PathBuf { + self.root_dir().join("build") + } } impl Default for Project {