Modified : now generates content regularly

This commit is contained in:
Justine 2023-01-16 11:57:12 +01:00
parent 522bcf3289
commit 1879af7230
3 changed files with 26 additions and 15 deletions

View File

@ -24,4 +24,4 @@ VOLUME ["/opt/flog/templates"]
EXPOSE 8000
# Run the application
CMD ["/usr/local/bin/flog-docker"]
CMD ["flog"]

View File

@ -17,7 +17,7 @@
<h1>Squi's awesome git blog</h1>
<h1>Squi's awesome blog</h1>
<p><img src="/pics/ferris.png" style="width:20%;"></p>
<br><br>
<h2>Lately on this great blog</h2>

View File

@ -4,6 +4,7 @@ use ssw::websrv::run_server;
use std::fs;
use std::env;
use std::collections::HashMap;
use std::{thread, time};
//1 - Ingest all the pages into a variable
// : all the pages must start with a number indicating their order
@ -92,15 +93,7 @@ fn generate_index(pages: (String, String),
fs::write(&index_path, index.as_str()).expect("Could not write index");
}
//#4
fn start_websrv(conf: WebsrvConfig) {
run_server(conf);
loop {
continue;
}
}
fn main() {
fn generate_content() -> String {
//Initialize from env variables
let root_path_env = "FLOG_ROOT_FOLDER";
let root_folder = match env::var(root_path_env) {
@ -115,18 +108,36 @@ fn main() {
let footer_path = format!("{html_folder_path}/footer.html");
let pages = match ingest_pages(&pages_path, &header_path, &footer_path, &html_folder_path) {
Some(p) => p,
None => (String::new(), String::new()),
Some(p) => {
println!("INFO : Generated site's content");
p
},
None => {
println!("ERR : No pages found, nothing to ingest");
(String::new(), String::new())
},
};
generate_index(pages, &index_template_path, &html_folder_path, &header_path, &footer_path);
return html_folder_path;
}
fn main() {
let html_folder = generate_content();
//Web conf
let webconf = WebsrvConfig {
nbr_of_threads: 10,
bind_addr: String::from("0.0.0.0:8000"),
root_folder: String::from(&html_folder_path),
root_folder: String::from(&html_folder),
};
start_websrv(webconf);
run_server(webconf);
loop {
let time_wait = time::Duration::from_secs(600);
thread::sleep(time_wait);
generate_content();
continue;
}
}