From 1879af7230d7e84d66cdc61f31ca2d253ef428e0 Mon Sep 17 00:00:00 2001 From: Justine Date: Mon, 16 Jan 2023 11:57:12 +0100 Subject: [PATCH] Modified : now generates content regularly --- Dockerfile | 2 +- base_site/html/index.html | 2 +- flog/src/main.rs | 37 ++++++++++++++++++++++++------------- 3 files changed, 26 insertions(+), 15 deletions(-) diff --git a/Dockerfile b/Dockerfile index 2938b80..0923792 100644 --- a/Dockerfile +++ b/Dockerfile @@ -24,4 +24,4 @@ VOLUME ["/opt/flog/templates"] EXPOSE 8000 # Run the application -CMD ["/usr/local/bin/flog-docker"] +CMD ["flog"] diff --git a/base_site/html/index.html b/base_site/html/index.html index 6be4ef7..00a92b3 100644 --- a/base_site/html/index.html +++ b/base_site/html/index.html @@ -17,7 +17,7 @@ -

Squi's awesome git blog

+

Squi's awesome blog



Lately on this great blog

diff --git a/flog/src/main.rs b/flog/src/main.rs index aeb582e..6eb0e36 100644 --- a/flog/src/main.rs +++ b/flog/src/main.rs @@ -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; + } + }