copy static files
This commit is contained in:
parent
5d89a8aebe
commit
1be561f6bd
28
src/main.rs
28
src/main.rs
|
@ -14,6 +14,7 @@ use roxy_tera_parser::{TeraParser, TeraParserOptions};
|
|||
|
||||
use clap::Parser as Clap;
|
||||
use std::{
|
||||
ffi,
|
||||
fs::{self, File},
|
||||
io::{BufReader, Read},
|
||||
path::{Path, PathBuf},
|
||||
|
@ -23,8 +24,6 @@ use toml::Table;
|
|||
use glob::glob;
|
||||
use roxy_core::roxy::{Parser, Roxy};
|
||||
|
||||
const DEFAULT_THEME: &'static str = "base16-ocean.dark";
|
||||
|
||||
fn handle_err<E: std::error::Error + 'static>(err: E) -> Error {
|
||||
Error::new(err.to_string(), err)
|
||||
}
|
||||
|
@ -88,6 +87,19 @@ fn context_from_meta_files<'a, T: AsRef<Path>>(
|
|||
Ok(context)
|
||||
}
|
||||
|
||||
fn copy_static<T: AsRef<Path>>(files: &Vec<&PathBuf>, file_path: &FilePath<T>) -> Result<(), Error> {
|
||||
for file in files {
|
||||
let output = file_path.to_output(file)?;
|
||||
fs::create_dir_all(output.parent().unwrap())?;
|
||||
fs::copy(file, file_path.to_output(file)?)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
const DEFAULT_THEME: &'static str = "base16-ocean.dark";
|
||||
const CONTENT_EXT: [&'static str; 4] = ["md", "tera", "html", "htm"];
|
||||
|
||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let opts = Options::parse();
|
||||
|
||||
|
@ -100,10 +112,18 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
let (meta, files): (Vec<&PathBuf>, Vec<&PathBuf>) =
|
||||
files.iter().partition(|f| f.extension().unwrap() == "toml");
|
||||
|
||||
let (content, files): (Vec<&PathBuf>, Vec<&PathBuf>) = files
|
||||
.iter()
|
||||
.partition(|f| {
|
||||
let ext = f.extension().and_then(ffi::OsStr::to_str).unwrap();
|
||||
CONTENT_EXT.contains(&ext)
|
||||
});
|
||||
|
||||
let mut context = context_from_meta_files(&meta, &file_path)?;
|
||||
|
||||
let theme = config.theme.unwrap_or(DEFAULT_THEME.to_string());
|
||||
for file in files {
|
||||
|
||||
for file in content {
|
||||
let file_name = file.with_extension("html");
|
||||
let output_path = file_path.to_output(&file_name)?;
|
||||
|
||||
|
@ -136,5 +156,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
Roxy::process_file(&file, &output_path, &mut parser).unwrap();
|
||||
}
|
||||
|
||||
copy_static(&files, &file_path)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue