context minimally working
This commit is contained in:
parent
fc38c360eb
commit
4116cb9728
54
Cargo.lock
generated
54
Cargo.lock
generated
|
@ -811,6 +811,8 @@ dependencies = [
|
|||
"glob",
|
||||
"roxy_core",
|
||||
"syntect",
|
||||
"tera",
|
||||
"toml",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -874,6 +876,15 @@ dependencies = [
|
|||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_spanned"
|
||||
version = "0.6.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "eb3622f419d1296904700073ea6cc23ad690adbd66f13ea683df73298736f0c1"
|
||||
dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sha2"
|
||||
version = "0.10.8"
|
||||
|
@ -1010,6 +1021,40 @@ dependencies = [
|
|||
"time-core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "toml"
|
||||
version = "0.8.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a1a195ec8c9da26928f773888e0742ca3ca1040c6cd859c919c9f59c1954ab35"
|
||||
dependencies = [
|
||||
"serde",
|
||||
"serde_spanned",
|
||||
"toml_datetime",
|
||||
"toml_edit",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "toml_datetime"
|
||||
version = "0.6.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3550f4e9685620ac18a50ed434eb3aec30db8ba93b0287467bca5826ea25baf1"
|
||||
dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "toml_edit"
|
||||
version = "0.21.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d34d383cd00a163b4a5b85053df514d45bc330f6de7737edfe0a93311d1eaa03"
|
||||
dependencies = [
|
||||
"indexmap",
|
||||
"serde",
|
||||
"serde_spanned",
|
||||
"toml_datetime",
|
||||
"winnow",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "typenum"
|
||||
version = "1.17.0"
|
||||
|
@ -1338,6 +1383,15 @@ version = "0.52.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04"
|
||||
|
||||
[[package]]
|
||||
name = "winnow"
|
||||
version = "0.5.34"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b7cf47b659b318dccbd69cc4797a39ae128f533dce7902a1096044d1967b9c16"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "yaml-rust"
|
||||
version = "0.4.5"
|
||||
|
|
|
@ -8,4 +8,6 @@ glob = "0.3.1"
|
|||
syntect = "5.1.0"
|
||||
roxy_core = { git = "https://github.com/kitsunecafe/roxy-core.git" }
|
||||
clap = { version = "4.4.17", features = ["derive"] }
|
||||
toml = "0.8.8"
|
||||
tera = "1.19.1"
|
||||
|
||||
|
|
32
src/main.rs
32
src/main.rs
|
@ -1,8 +1,10 @@
|
|||
use clap::Parser as Clap;
|
||||
use std::{
|
||||
io::{Error, ErrorKind},
|
||||
fs::File,
|
||||
io::{BufReader, Error, ErrorKind, Read},
|
||||
path::{Path, PathBuf, StripPrefixError},
|
||||
};
|
||||
use toml::Table;
|
||||
|
||||
use glob::{glob, PatternError};
|
||||
use roxy_core::roxy::{Html, Markdown, Parser, Roxy};
|
||||
|
@ -108,13 +110,33 @@ impl<'a, P: AsRef<Path> + 'a> FilePath<'a, P> {
|
|||
|
||||
fn main() -> Result<(), RoxyError> {
|
||||
let opts = Options::parse();
|
||||
|
||||
let file_path = FilePath::new(&opts.input, &opts.output);
|
||||
let files = get_files(&file_path.input)?;
|
||||
let (meta, files): (Vec<&PathBuf>, Vec<&PathBuf>) =
|
||||
files.iter().partition(|f| f.extension().unwrap() == "toml");
|
||||
|
||||
let mut context = tera::Context::new();
|
||||
for path in meta {
|
||||
let mut buf = Vec::new();
|
||||
|
||||
let mut file = File::open(path).map(BufReader::new).unwrap();
|
||||
file.read_to_end(&mut buf).unwrap();
|
||||
let mut str = String::from_utf8(buf).unwrap();
|
||||
let toml: Table = toml::from_str(&mut str).unwrap();
|
||||
|
||||
for (k, v) in toml.iter() {
|
||||
context.insert(k, v);
|
||||
}
|
||||
}
|
||||
|
||||
let mut parser = Parser::new();
|
||||
parser.push(Markdown::new());
|
||||
let html = Html::default();
|
||||
parser.push(html);
|
||||
let file_path = FilePath::new(&opts.input, &opts.output);
|
||||
|
||||
for file in get_files(&file_path.input)? {
|
||||
let html = Html::new(tera::Tera::default(), context);
|
||||
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);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue