This commit is contained in:
2026-01-16 10:12:45 +00:00
parent 32b0b62fef
commit 23a5d5596e
3 changed files with 22 additions and 4 deletions

1
TODO.txt Normal file
View File

@@ -0,0 +1 @@
Add global vars to the env context, then add vars from user defined config.toml to the env context...

View File

@@ -34,6 +34,7 @@ pub struct Header {
r#type: String, r#type: String,
title: Option<String>, title: Option<String>,
pub path: Option<String>, pub path: Option<String>,
pub file_path: Option<String>,
// TODO impl this later // TODO impl this later
// extras: Table, // extras: Table,
} }
@@ -66,7 +67,8 @@ impl AppState<'_> {
config_path.push("config.toml"); config_path.push("config.toml");
let config_file = fs::read_to_string(config_path).await?; let config_file = fs::read_to_string(config_path).await?;
let header: Header = toml::from_str(&config_file)?; let mut header: Header = toml::from_str(&config_file)?;
header.file_path = Some(entry.path().to_str().unwrap().to_string());
let mut index = entry.path(); let mut index = entry.path();
index.push("index.html"); index.push("index.html");
@@ -80,6 +82,24 @@ impl AppState<'_> {
continue; continue;
} }
let page = Page { header: header }; let page = Page { header: header };
let mut error_out = false;
for x in &self.pages {
if x.header.id == page.header.id {
println!(
"{:#?} has the same id as {:#?} !! not loading this page",
entry.path(),
x.header.file_path.unwrap()
);
error_out = true;
break;
}
}
if error_out {
continue;
}
self.pages.push(page); self.pages.push(page);
} else { } else {
println!("Not parsing {}", entry.file_name().to_str().unwrap()); println!("Not parsing {}", entry.file_name().to_str().unwrap());

View File

@@ -72,9 +72,6 @@ async fn listen(
listener: Async<TcpListener>, listener: Async<TcpListener>,
state: Arc<AppState<'static>>, state: Arc<AppState<'static>>,
) -> Result<()> { ) -> Result<()> {
// Format the full host address.
// println!("Listening on {}", host);
loop { loop {
// Wait for a new client. // Wait for a new client.
let (client, _) = listener.accept().await?; let (client, _) = listener.accept().await?;