]> git.r.bdr.sh - rbdr/page/blob - src/file_handler/file_strategies/file.rs
Remove clang from page
[rbdr/page] / src / file_handler / file_strategies / file.rs
1 pub struct Strategy {}
2
3 use std::path::PathBuf;
4 use std::fs::{copy, create_dir_all};
5
6 use crate::file_handler::{File, FileType, FileHandlerStrategy};
7
8 impl Strategy {
9 fn handle(&self, source: &PathBuf, destination: &PathBuf, file: &File) {
10 let relative_path = file.path.strip_prefix(&source).unwrap();
11 let complete_destination = destination.join(relative_path);
12 let destination_parent = complete_destination.parent().unwrap();
13 create_dir_all(destination_parent).unwrap();
14 copy(&file.path, &complete_destination).unwrap();
15 }
16 }
17
18 impl FileHandlerStrategy for Strategy {
19 fn is(&self, path: &PathBuf) -> bool {
20 !path.is_dir()
21 }
22
23 fn identify(&self) -> FileType {
24 FileType::File
25 }
26
27 fn can_handle(&self, file_type: &FileType) -> bool {
28 match file_type {
29 FileType::File => true,
30 _ => false,
31 }
32 }
33
34 fn handle_html(&self, source: &PathBuf, destination: &PathBuf, file: &File, _l: &String) {
35 return self.handle(source, destination, file);
36 }
37
38 fn handle_gemini(&self, source: &PathBuf, destination: &PathBuf, file: &File) {
39 return self.handle(source, destination, file);
40 }
41 }