update risp

This commit is contained in:
2024-02-17 10:55:38 +01:00
parent 42150a6561
commit 72f22efd02
23 changed files with 226 additions and 216 deletions

View File

@ -6,13 +6,13 @@ fn print_content(content: Content) -> String {
let mut ret = String::new();
match content {
Content::Text(t) => ret.push_str(&format!("<div class='content text'>{t}</div>")),
Content::Text(t) => ret.push_str(&format!("<li>{t}</li>")),
Content::Item(l) | Content::List(l) => {
ret.push_str("<span class='content list'>");
ret.push_str("<ul class='content list'>");
for item in l {
ret.push_str(&print_content(item));
}
ret.push_str("</span>");
ret.push_str("</ul>");
}
}
@ -68,15 +68,15 @@ fn print_header(header: Heading, level: usize) -> String {
ret
}
fn get_content(config_path: &str) -> String {
fn get_content(config_path: &str) -> (String, String) {
let law = Law::from_config(config_path).unwrap();
let lawname = law.name;
let mut ret = String::new();
for h in law.header {
ret.push_str(&print_header(h, 0));
}
ret
(lawname, ret)
}
fn main() {
@ -89,12 +89,12 @@ fn main() {
let law_name = filename.replace(".toml", "");
let path = format!("{}", config.path().display());
let content = get_content(&path);
let (lawname, content) = get_content(&path);
let template = fs::read_to_string("templates/index.html").unwrap();
let site = template
.replace("{{content}}", &content)
.replace("{{title}}", &law_name);
.replace("{{title}}", &lawname);
fs::write(&format!("output/{law_name}.html"), &site).expect("Unable to write file");
}