diff options
| -rw-r--r-- | Makefile | 8 | ||||
| -rw-r--r-- | README.gmi | 8 | ||||
| -rw-r--r-- | src/file_handler/mod.rs | 6 | ||||
| -rw-r--r-- | src/main.rs | 9 |
4 files changed, 27 insertions, 4 deletions
diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..b64b6e2 --- /dev/null +++ b/Makefile @@ -0,0 +1,8 @@ +profile = dev + +default: build + +build: + cargo build --profile $(profile) + +.PHONY: build @@ -59,3 +59,11 @@ in the directory. ## What happens to files that aren't gemini? They're copied as-is. + +# Building + +This project is built using cargo. A makefile is provided to run common tasks. + +Build dev version with `make` or `make build`. + +Build release with `make -e profile=release` or `make -e profile=release build`. diff --git a/src/file_handler/mod.rs b/src/file_handler/mod.rs index a106c27..4932ef1 100644 --- a/src/file_handler/mod.rs +++ b/src/file_handler/mod.rs @@ -35,18 +35,18 @@ impl FileHandler { FileType::Unknown } - pub fn get_layout_or_panic(&mut self, files: &Vec<File>) { + pub fn get_layout_or_panic(&mut self, files: &Vec<File>) -> Result<(), &str> { for file in files { match file.file_type { FileType::Layout => { let layout_text = read_to_string(&file.path).unwrap(); self.layout = Some(layout_text); - return; + return Ok(()); }, _ => {} } } - panic!("No layout found. Please ensure there's a _layout.html file at the root"); + Err("No layout found. Please ensure there's a _layout.html file at the root") } pub fn handle_all(&self, source: &PathBuf, destination: &PathBuf, files: &Vec<File>) { diff --git a/src/main.rs b/src/main.rs index fdfe863..c6de435 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,6 +3,7 @@ mod file_finder; mod file_handler; use std::io::Result; +use std::process::exit; use std::env::current_dir; use std::fs::{create_dir_all, remove_dir_all}; @@ -27,7 +28,13 @@ fn main() -> Result<()> { // Step 3. Load the layout let mut file_handler = FileHandler::default(); - file_handler.get_layout_or_panic(&files); + match file_handler.get_layout_or_panic(&files) { + Ok(_) => {}, + Err(error) => { + eprintln!("{}", error); + exit(1); + } + } // Step 4. Process all files file_handler.handle_all(&source, &destination, &files); |