]>
Commit | Line | Data |
---|---|---|
1 | mod file_finder; | |
2 | mod file_handler; | |
3 | ||
4 | use std::env::current_dir; | |
5 | use std::fs::{create_dir_all, remove_dir_all}; | |
6 | use std::io::Result; | |
7 | use std::process::exit; | |
8 | ||
9 | use crate::file_finder::find_files; | |
10 | use crate::file_handler::FileHandler; | |
11 | ||
12 | fn main() -> Result<()> { | |
13 | let source = current_dir()?; | |
14 | let source_name = source.file_name().unwrap().to_string_lossy(); | |
15 | let parent = source.parent().unwrap(); | |
16 | let gemini_destination_name = format!("{source_name}_gemini"); | |
17 | let gemini_destination = parent.join(gemini_destination_name); | |
18 | let html_destination_name = format!("{source_name}_html"); | |
19 | let html_destination = parent.join(html_destination_name); | |
20 | ||
21 | // Step 1. Identify the files | |
22 | let files = find_files(&source); | |
23 | ||
24 | // Step 2. Load the layout | |
25 | let mut file_handler = FileHandler::default(); | |
26 | match file_handler.get_layout_or_panic(&files) { | |
27 | Ok(()) => {} | |
28 | Err(error) => { | |
29 | eprintln!("{error}"); | |
30 | exit(1); | |
31 | } | |
32 | } | |
33 | ||
34 | // Step 3. Prepare the target priority | |
35 | let _ = remove_dir_all(&html_destination); | |
36 | let _ = remove_dir_all(&gemini_destination); | |
37 | ||
38 | create_dir_all(&html_destination).expect("Could not create HTML directory."); | |
39 | create_dir_all(&gemini_destination).expect("Could not create Gemini directory."); | |
40 | ||
41 | // Step 4. Process all files | |
42 | file_handler.handle_all(&source, &html_destination, &gemini_destination, &files); | |
43 | Ok(()) | |
44 | } |