|
|
@ -1,3 +1,4 @@
|
|
|
|
|
|
|
|
use deunicode::deunicode;
|
|
|
|
use structopt::StructOpt;
|
|
|
|
use structopt::StructOpt;
|
|
|
|
use toml::Value;
|
|
|
|
use toml::Value;
|
|
|
|
|
|
|
|
|
|
|
@ -35,12 +36,12 @@ fn replace(mut template: String, rules: &[(String, String)]) -> String {
|
|
|
|
|
|
|
|
|
|
|
|
/// collects table into a vector of String pairs
|
|
|
|
/// collects table into a vector of String pairs
|
|
|
|
fn collect_table(table: &Value) -> Vec<(String, String)> {
|
|
|
|
fn collect_table(table: &Value) -> Vec<(String, String)> {
|
|
|
|
table.as_table()
|
|
|
|
table
|
|
|
|
|
|
|
|
.as_table()
|
|
|
|
.unwrap()
|
|
|
|
.unwrap()
|
|
|
|
.keys()
|
|
|
|
.keys()
|
|
|
|
.map(
|
|
|
|
.map(|x| (x.clone(), String::from(table[x].as_str().unwrap())))
|
|
|
|
|x| (x.clone(), String::from(table[x].as_str().unwrap()))
|
|
|
|
.collect()
|
|
|
|
).collect()
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
fn main() {
|
|
|
@ -63,14 +64,19 @@ fn main() {
|
|
|
|
&[opt.template, PathBuf::from("front.html")]
|
|
|
|
&[opt.template, PathBuf::from("front.html")]
|
|
|
|
.iter()
|
|
|
|
.iter()
|
|
|
|
.collect::<PathBuf>(),
|
|
|
|
.collect::<PathBuf>(),
|
|
|
|
).unwrap();
|
|
|
|
)
|
|
|
|
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
|
|
|
|
// create rules
|
|
|
|
// create rules
|
|
|
|
// hope to god the toml is correctly formatted
|
|
|
|
// hope to god the toml is correctly formatted
|
|
|
|
|
|
|
|
|
|
|
|
// start with removing page rules
|
|
|
|
// start with removing page rules
|
|
|
|
let page = value.as_table_mut().unwrap().remove("page").unwrap().clone();
|
|
|
|
let page = value
|
|
|
|
|
|
|
|
.as_table_mut()
|
|
|
|
|
|
|
|
.unwrap()
|
|
|
|
|
|
|
|
.remove("page")
|
|
|
|
|
|
|
|
.unwrap()
|
|
|
|
|
|
|
|
.clone();
|
|
|
|
|
|
|
|
|
|
|
|
// collect global rules into a vec
|
|
|
|
// collect global rules into a vec
|
|
|
|
let global = collect_table(&value);
|
|
|
|
let global = collect_table(&value);
|
|
|
@ -78,18 +84,40 @@ fn main() {
|
|
|
|
// iterate over pages
|
|
|
|
// iterate over pages
|
|
|
|
for (index, value) in page.as_array().unwrap().iter().enumerate() {
|
|
|
|
for (index, value) in page.as_array().unwrap().iter().enumerate() {
|
|
|
|
// add global variables to table
|
|
|
|
// add global variables to table
|
|
|
|
// FIXME
|
|
|
|
|
|
|
|
let mut table = collect_table(&value);
|
|
|
|
let mut table = collect_table(&value);
|
|
|
|
table.extend(global.clone());
|
|
|
|
table.extend(global.clone());
|
|
|
|
|
|
|
|
// TODO make this less of a pain
|
|
|
|
let content = replace(input.clone(), table.as_slice());
|
|
|
|
let content = replace(input.clone(), table.as_slice());
|
|
|
|
|
|
|
|
|
|
|
|
// create the files
|
|
|
|
// create the files
|
|
|
|
let target = format!("front-{}.html", index);
|
|
|
|
let (code, day, time_start) = (
|
|
|
|
|
|
|
|
value["code"].as_str().unwrap(),
|
|
|
|
|
|
|
|
value["day"].as_str().unwrap(),
|
|
|
|
|
|
|
|
value["time_start"].as_str().unwrap(),
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
// tweaks
|
|
|
|
|
|
|
|
// day
|
|
|
|
|
|
|
|
let mut day = String::from(day);
|
|
|
|
|
|
|
|
day = deunicode(&day).to_uppercase();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// time_start
|
|
|
|
|
|
|
|
let mut time_start = String::from(time_start);
|
|
|
|
|
|
|
|
time_start = time_start.replace(":", "");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// code
|
|
|
|
|
|
|
|
let code = String::from(code).replace(" ", "-");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let target = format!("PREZ_{}_{}_{}.html", code, &day[0..2], time_start);
|
|
|
|
|
|
|
|
|
|
|
|
println!("writing {}", target);
|
|
|
|
println!("writing {}", target);
|
|
|
|
write(&[&opt.output, &PathBuf::from(target)].iter().collect::<PathBuf>(), content)
|
|
|
|
write(
|
|
|
|
.unwrap();
|
|
|
|
&[&opt.output, &PathBuf::from(target)]
|
|
|
|
|
|
|
|
.iter()
|
|
|
|
|
|
|
|
.collect::<PathBuf>(),
|
|
|
|
|
|
|
|
content,
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
.unwrap();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//println!("{:#?}", global);
|
|
|
|
//println!("{:#?}", global);
|
|
|
|
}
|
|
|
|
}
|
|
|
|