add index page
All checks were successful
CI/CD Pipeline / deploy-main (push) Successful in 7s

This commit is contained in:
philipp 2024-02-17 16:11:16 +01:00
parent 48a6cc8fda
commit 94aa3dd54e
3 changed files with 29 additions and 4 deletions

View File

@ -84,6 +84,7 @@ fn get_content(config_path: &str) -> (String, String) {
fn main() { fn main() {
let configs = fs::read_dir("./laws").expect("No folder with config files"); let configs = fs::read_dir("./laws").expect("No folder with config files");
let mut li_of_files = String::new();
for config in configs { for config in configs {
let config = config.unwrap(); let config = config.unwrap();
let filename = config.file_name().into_string().unwrap(); let filename = config.file_name().into_string().unwrap();
@ -93,11 +94,14 @@ fn main() {
let path = format!("{}", config.path().display()); let path = format!("{}", config.path().display());
let (lawname, content) = get_content(&path); let (lawname, content) = get_content(&path);
let template = fs::read_to_string("templates/index.html").unwrap(); let template = fs::read_to_string("templates/law.html").unwrap();
let site = template let site = template
.replace("{{content}}", &content) .replace("{{content}}", &content)
.replace("{{title}}", &lawname); .replace("{{title}}", &lawname);
li_of_files.push_str(&format!(
"<li><a href='./{law_name}'>{lawname}</a></li><br />\n"
));
fs::write(&format!("output/{law_name}.html"), &site).expect("Unable to write file"); fs::write(&format!("output/{law_name}.html"), &site).expect("Unable to write file");
} }
let style = fs::read_to_string("templates/style.css").unwrap(); let style = fs::read_to_string("templates/style.css").unwrap();
@ -105,4 +109,8 @@ fn main() {
let style = fs::read_to_string("templates/pico.min.css").unwrap(); let style = fs::read_to_string("templates/pico.min.css").unwrap();
fs::write(&format!("output/pico.min.css"), &style).expect("Unable to write file"); fs::write(&format!("output/pico.min.css"), &style).expect("Unable to write file");
let mut index = fs::read_to_string("templates/index.html").unwrap();
index = index.replace("{{content}}", &li_of_files);
fs::write(&format!("output/index.html"), &index).expect("Unable to write file");
} }

View File

@ -6,10 +6,9 @@
</head> </head>
<body> <body>
<div class="container"> <div class="container">
<button onclick='openAll();'>Open all</button> <ol>
<button onclick='closeAll();'>Close all</button>
<h1>{{title}}</h1>
{{content}} {{content}}
</ol>
</div> </div>
<script> <script>

18
templates/law.html Normal file
View File

@ -0,0 +1,18 @@
<html>
<head>
<link rel="stylesheet" href="pico.min.css" />
<link rel="stylesheet" href="style.css" />
<meta charset="UTF-8">
</head>
<body>
<div class="container">
<button onclick='openAll();'>Open all</button>
<button onclick='closeAll();'>Close all</button>
<h1>{{title}}</h1>
{{content}}
</div>
<script>
</script>
</body>
</html>