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