]> git.r.bdr.sh - rbdr/page/blame - src/main.rs
Handle layout error better
[rbdr/page] / src / main.rs
CommitLineData
8d4fac52 1mod gemini_parser;
1e2d00b6
RBR
2mod file_finder;
3mod file_handler;
4
4fd89b80 5use std::io::Result;
48ea9080 6use std::process::exit;
1e2d00b6 7use std::env::current_dir;
ea529736 8use std::fs::{create_dir_all, remove_dir_all};
8d4fac52 9
1e2d00b6 10use crate::file_finder::find_files;
4fd89b80 11use crate::file_handler::FileHandler;
8d4fac52 12
4fd89b80 13fn main() -> Result<()> {
4fd89b80
RBR
14 let source = current_dir()?;
15 let source_name = source.file_name().unwrap().to_string_lossy();
16 let parent = source.parent().unwrap();
17 let destination_name = format!("{}_html", source_name);
18 let destination = parent.join(destination_name);
19
20 // Step 1. Identify the files
21 let files = find_files(&source);
22
23 // Step 2. Prepare the target priority
ea529736
RBR
24 match remove_dir_all(&destination) {
25 _ => {}
26 };
4fd89b80
RBR
27 create_dir_all(&destination)?;
28
4fd89b80
RBR
29 // Step 3. Load the layout
30 let mut file_handler = FileHandler::default();
48ea9080
RBR
31 match file_handler.get_layout_or_panic(&files) {
32 Ok(_) => {},
33 Err(error) => {
34 eprintln!("{}", error);
35 exit(1);
36 }
37 }
4fd89b80
RBR
38
39 // Step 4. Process all files
40 file_handler.handle_all(&source, &destination, &files);
41 Ok(())
8d4fac52 42}