From fa9997a650149efa286081a84042251ce9a633a6 Mon Sep 17 00:00:00 2001 From: Olivia Brooks <109807080+Cutieguwu@users.noreply.github.com> Date: Mon, 13 Oct 2025 20:43:56 -0400 Subject: [PATCH] Switch to convert.rs from webp.rs; migrate md to html conversion there. --- src/convert.rs | 28 ++++++++++++++++++++++++++++ src/main.rs | 44 ++++++++++++++++++-------------------------- src/webp.rs | 12 ------------ 3 files changed, 46 insertions(+), 38 deletions(-) create mode 100644 src/convert.rs delete mode 100644 src/webp.rs diff --git a/src/convert.rs b/src/convert.rs new file mode 100644 index 0000000..93019b1 --- /dev/null +++ b/src/convert.rs @@ -0,0 +1,28 @@ +use std::io::Read; +use std::path::Path; + +use image::ImageReader; +use markdown; + +pub fn to_webp(path: &Path) -> Result<(), Box> { + ImageReader::open(path)?.decode()?.save(format!( + "{}.webp", + path.file_stem().unwrap().to_str().unwrap() + ))?; + + Ok(()) +} + +pub fn md_to_html(path: &Path) -> Result { + let mut buf = String::new(); + + // Loading and Converting post.md to html + std::fs::OpenOptions::new() + .read(true) // Just ensure that file opens read-only. + .open(path) + .expect("Failed to open single_post file") + .read_to_string(&mut buf) + .expect("Failed to read single_post file to string"); + + markdown::to_html_with_options(&buf, &markdown::Options::gfm()) +} diff --git a/src/main.rs b/src/main.rs index 85ba1f3..7e4fc0f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,23 +1,25 @@ mod blog; mod cli; +mod convert; mod error; mod og; -mod webp; use crate::blog::Meta; -use std::io::Read; use clap::Parser; -use markdown; fn main() { let config = cli::Args::parse(); - // Fallback Meta Setup - blog::FALLBACK_META_PATH.get_or_init(|| config.fallback_meta); + load_fb_meta(&config); - let _fb_meta = Meta::default(); - println!("Loaded FallbackMeta"); + convert::md_to_html( + config + .single_post + .expect("No path for single post processing") + .as_path(), + ) + .expect("Failed to convert single_post to html"); // Loading meta.ron files process. let _meta = Meta::try_from( @@ -28,23 +30,13 @@ fn main() { .as_path(), ) .expect("Failed to deserialize single_meta file"); - - // Loading and Converting post.md to html - let mut md_post = std::fs::OpenOptions::new() - .read(true) // Just ensure that file opens read-only. - .open( - config - .single_post - .expect("No path for single post processing"), - ) - .expect("Failed to open single_post file"); - let mut buf = String::new(); - md_post - .read_to_string(&mut buf) - .expect("Failed to read single_post file to string"); - - let html_post = markdown::to_html_with_options(&buf, &markdown::Options::gfm()) - .expect("Failed to convert single_post file to html"); - - dbg!(html_post); +} + +/// Fallback Meta Setup +fn load_fb_meta(config: &cli::Args) { + blog::FALLBACK_META_PATH.get_or_init(|| config.fallback_meta.to_owned()); + + // Trigger OnceLock loading of fallback_meta path. + Meta::default(); + println!("Loaded FallbackMeta"); } diff --git a/src/webp.rs b/src/webp.rs deleted file mode 100644 index 44dfe3a..0000000 --- a/src/webp.rs +++ /dev/null @@ -1,12 +0,0 @@ -use std::path::Path; - -use image::ImageReader; - -fn to_webp(path: &Path) -> Result<(), Box> { - ImageReader::open(path)?.decode()?.save(format!( - "{}.webp", - path.file_stem().unwrap().to_str().unwrap() - ))?; - - Ok(()) -}