]>
Commit | Line | Data |
---|---|---|
1e2d00b6 RBR |
1 | mod file_finder; |
2 | mod file_handler; | |
3 | ||
4 | use std::env::current_dir; | |
ea529736 | 5 | use std::fs::{create_dir_all, remove_dir_all}; |
5732d284 RBR |
6 | use std::io::Result; |
7 | use std::process::exit; | |
8d4fac52 | 8 | |
1e2d00b6 | 9 | use crate::file_finder::find_files; |
4fd89b80 | 10 | use crate::file_handler::FileHandler; |
8d4fac52 | 11 | |
4fd89b80 | 12 | fn main() -> Result<()> { |
4fd89b80 RBR |
13 | let source = current_dir()?; |
14 | let source_name = source.file_name().unwrap().to_string_lossy(); | |
15 | let parent = source.parent().unwrap(); | |
8766e441 | 16 | let gemini_destination_name = format!("{source_name}_gemini"); |
dd0a540c | 17 | let gemini_destination = parent.join(gemini_destination_name); |
8766e441 | 18 | let html_destination_name = format!("{source_name}_html"); |
dd0a540c | 19 | let html_destination = parent.join(html_destination_name); |
4fd89b80 RBR |
20 | |
21 | // Step 1. Identify the files | |
22 | let files = find_files(&source); | |
23 | ||
1c5797fa | 24 | // Step 2. Load the layout |
4fd89b80 | 25 | let mut file_handler = FileHandler::default(); |
48ea9080 | 26 | match file_handler.get_layout_or_panic(&files) { |
8766e441 | 27 | Ok(()) => {} |
48ea9080 | 28 | Err(error) => { |
8766e441 | 29 | eprintln!("{error}"); |
48ea9080 RBR |
30 | exit(1); |
31 | } | |
32 | } | |
4fd89b80 | 33 | |
1c5797fa | 34 | // Step 3. Prepare the target priority |
5732d284 RBR |
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."); | |
1c5797fa | 40 | |
4fd89b80 | 41 | // Step 4. Process all files |
dd0a540c | 42 | file_handler.handle_all(&source, &html_destination, &gemini_destination, &files); |
4fd89b80 | 43 | Ok(()) |
8d4fac52 | 44 | } |