diff --git a/Cargo.lock b/Cargo.lock index 2537e45..00e83de 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -810,6 +810,9 @@ dependencies = [ "clap", "glob", "roxy_core", + "roxy_markdown_parser", + "roxy_markdown_tera_goop", + "roxy_tera_parser", "serde", "syntect", "tera", @@ -825,6 +828,29 @@ dependencies = [ "tera", ] +[[package]] +name = "roxy_markdown_parser" +version = "0.1.0" +dependencies = [ + "pulldown-cmark", + "roxy_core", +] + +[[package]] +name = "roxy_markdown_tera_goop" +version = "0.1.0" +dependencies = [ + "roxy_core", +] + +[[package]] +name = "roxy_tera_parser" +version = "0.1.0" +dependencies = [ + "roxy_core", + "tera", +] + [[package]] name = "ryu" version = "1.0.16" diff --git a/Cargo.toml b/Cargo.toml index 5256464..23f2e13 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,6 +6,10 @@ edition = "2021" [dependencies] glob = "0.3.1" syntect = "5.1.0" +#roxy_core = { path = "../roxy-core/" } +roxy_markdown_parser = { path = "../roxy-markdown-parser/" } +roxy_tera_parser = { path = "../roxy-tera-parser/" } +roxy_markdown_tera_goop = { path = "../roxy-markdown-tera-goop/" } roxy_core = { git = "https://github.com/kitsunecafe/roxy-core.git" } clap = { version = "4.4.17", features = ["derive"] } toml = "0.8.8" diff --git a/src/main.rs b/src/main.rs index e715ba5..a1dc094 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,7 @@ use clap::Parser as Clap; +use roxy_markdown_parser::MarkdownParser; +use roxy_tera_parser::TeraParser; +use roxy_markdown_tera_goop::MarkdownTeraParser; use std::{ fs::File, io::{BufReader, Error, ErrorKind, Read}, @@ -7,7 +10,7 @@ use std::{ use toml::Table; use glob::{glob, PatternError}; -use roxy_core::roxy::{Html, Markdown, Parser, Roxy}; +use roxy_core::roxy::{Parse, Parser, Roxy}; #[derive(Clap)] #[command(name = "Roxy")] @@ -120,15 +123,21 @@ impl Context { } } - fn insert>(&mut self, path: &P, meta: Table) { - let path = path - .as_ref() + fn normalize_path>(path: &P) -> String { + path.as_ref() .with_extension("") .to_string_lossy() .split(path::MAIN_SEPARATOR_STR) - .fold(String::new(), |a, b| format!("{a}.{b}")); + .fold(String::new(), |a, b| format!("{a}.{b}")) + } - self.inner.insert(path.trim_start_matches('.'), &meta); + fn insert>(&mut self, path: &P, meta: Table) { + self.inner + .insert(Self::normalize_path(path).trim_start_matches('.'), &meta); + } + + fn get>(&self, path: &P) -> Option<&tera::Value> { + self.inner.get(&Self::normalize_path(path)) } } @@ -153,14 +162,19 @@ fn main() -> Result<(), RoxyError> { } let mut parser = Parser::new(); - parser.push(Markdown::new()); + parser.push(MarkdownParser::new()); - let html = Html::new(tera::Tera::default(), context.inner); + let goop = MarkdownTeraParser::new(); + parser.push(goop); + + let tera = tera::Tera::default(); + let html = TeraParser::new(tera, context.inner); parser.push(html); + for file in files { let file_name = file.with_extension("html"); - let _ = Roxy::process_file(&file, &(&file_path.to_output(&file_name)?), &mut parser); + Roxy::process_file(&file, &(&file_path.to_output(&file_name)?), &mut parser).unwrap(); } Ok(())