|
|
|
@ -2,7 +2,7 @@ use structopt::StructOpt;
|
|
|
|
|
use toml::Value;
|
|
|
|
|
|
|
|
|
|
use std::collections::hash_map::DefaultHasher;
|
|
|
|
|
use std::fs::{copy, create_dir, read_to_string, write};
|
|
|
|
|
use std::fs::{copy, create_dir, read_to_string};
|
|
|
|
|
use std::path::PathBuf;
|
|
|
|
|
|
|
|
|
|
#[derive(StructOpt, Debug)]
|
|
|
|
@ -25,7 +25,7 @@ struct Opt {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// replaces {{ value }} with actual value
|
|
|
|
|
fn replace(mut template: String, rules: &[(String, String)]) -> String {
|
|
|
|
|
fn replace(mut template: String, rules: &[(&str, &str)]) -> String {
|
|
|
|
|
for (x, y) in rules {
|
|
|
|
|
let l = format!("{{{{ {} }}}}", x);
|
|
|
|
|
template = template.replace(&l, y)
|
|
|
|
@ -60,10 +60,10 @@ fn main() {
|
|
|
|
|
|
|
|
|
|
// read template
|
|
|
|
|
let input = read_to_string(
|
|
|
|
|
&[opt.template, PathBuf::from("front.html")]
|
|
|
|
|
&[opt.output, PathBuf::from("front.html")]
|
|
|
|
|
.iter()
|
|
|
|
|
.collect::<PathBuf>(),
|
|
|
|
|
).unwrap();
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// create rules
|
|
|
|
@ -76,15 +76,10 @@ fn main() {
|
|
|
|
|
let global = collect_table(&value);
|
|
|
|
|
|
|
|
|
|
// iterate over pages
|
|
|
|
|
for (index, value) in page.as_array().unwrap().iter().enumerate() {
|
|
|
|
|
let table = collect_table(&value);
|
|
|
|
|
for i in page.as_array().unwrap() {
|
|
|
|
|
println!("{:?}", i);
|
|
|
|
|
|
|
|
|
|
let content = replace(input.clone(), table.as_slice());
|
|
|
|
|
|
|
|
|
|
// create the files
|
|
|
|
|
let target = format!("front-{}.html", index);
|
|
|
|
|
println!("writing {}", target);
|
|
|
|
|
write(&[&opt.output, &PathBuf::from(target)].iter().collect::<PathBuf>(), content);
|
|
|
|
|
// TODO create the files
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//println!("{:#?}", global);
|
|
|
|
|