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