]> git.r.bdr.sh - rbdr/page/blame - src/main.rs
Add first tests
[rbdr/page] / src / main.rs
CommitLineData
8d4fac52 1mod gemini_parser;
260e8ec6 2mod html_renderer;
1e2d00b6
RBR
3mod file_finder;
4mod file_handler;
5
4fd89b80 6use std::io::Result;
48ea9080 7use std::process::exit;
1e2d00b6 8use std::env::current_dir;
ea529736 9use std::fs::{create_dir_all, remove_dir_all};
8d4fac52 10
1e2d00b6 11use crate::file_finder::find_files;
4fd89b80 12use crate::file_handler::FileHandler;
8d4fac52 13
4fd89b80 14fn 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();
dd0a540c
RBR
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);
4fd89b80
RBR
22
23 // Step 1. Identify the files
24 let files = find_files(&source);
25
26 // Step 2. Prepare the target priority
dd0a540c 27 match remove_dir_all(&html_destination) {
ea529736
RBR
28 _ => {}
29 };
dd0a540c
RBR
30 create_dir_all(&html_destination)?;
31 match remove_dir_all(&gemini_destination) {
32 _ => {}
33 };
34 create_dir_all(&gemini_destination)?;
4fd89b80 35
4fd89b80
RBR
36 // Step 3. Load the layout
37 let mut file_handler = FileHandler::default();
48ea9080
RBR
38 match file_handler.get_layout_or_panic(&files) {
39 Ok(_) => {},
40 Err(error) => {
41 eprintln!("{}", error);
42 exit(1);
43 }
44 }
4fd89b80
RBR
45
46 // Step 4. Process all files
dd0a540c 47 file_handler.handle_all(&source, &html_destination, &gemini_destination, &files);
4fd89b80 48 Ok(())
8d4fac52 49}