X-Git-Url: https://git.r.bdr.sh/rbdr/page/blobdiff_plain/68fa37d61babe8d990ace5f9cb5a7de81eb57ea0..0209ed07ce2b2561a4b10e3db5d8525bf3d3545d:/src/file_handler/file_strategies/gemini.rs diff --git a/src/file_handler/file_strategies/gemini.rs b/src/file_handler/file_strategies/gemini.rs index 04e2b6a..977464c 100644 --- a/src/file_handler/file_strategies/gemini.rs +++ b/src/file_handler/file_strategies/gemini.rs @@ -44,7 +44,7 @@ impl FileHandlerStrategy for Strategy { } } - fn handle(&self, source: &PathBuf, destination: &PathBuf, file: &File, layout: &String) { + fn handle_html(&self, source: &PathBuf, destination: &PathBuf, file: &File, layout: &String) { let gemini_contents = read_to_string(&file.path).unwrap(); // Front matter extraction @@ -75,11 +75,40 @@ impl FileHandlerStrategy for Strategy { let relative_path = file.path.strip_prefix(&source).unwrap(); - let complete_destination = destination.join(relative_path); + let mut complete_destination = destination.join(relative_path); + complete_destination.set_extension("html"); let destination_parent = complete_destination.parent().unwrap(); create_dir_all(destination_parent).unwrap(); let mut destination_file = IOFile::create(&complete_destination).unwrap(); destination_file.write_all(generated_html.as_bytes()).unwrap(); } + + fn handle_gemini(&self, source: &PathBuf, destination: &PathBuf, file: &File) { + let gemini_contents = read_to_string(&file.path).unwrap(); + + // Front matter extraction + let lines: Vec<&str> = gemini_contents.split("\n").collect(); + let mut lines_found = 0; + for line in lines[..2].iter() { + if self.is_title(&line) { + lines_found = lines_found + 1; + continue; + } + if self.is_description(&line) { + lines_found = lines_found + 1; + continue; + } + } + + let gemini_source = lines[lines_found..].join("\n"); + + let relative_path = file.path.strip_prefix(&source).unwrap(); + let complete_destination = destination.join(relative_path); + let destination_parent = complete_destination.parent().unwrap(); + create_dir_all(destination_parent).unwrap(); + + let mut destination_file = IOFile::create(&complete_destination).unwrap(); + destination_file.write_all(gemini_source.as_bytes()).unwrap(); + } }