awesome pawsome

This commit is contained in:
2026-01-13 20:28:42 +00:00
parent cced229c5e
commit 32b0b62fef
8 changed files with 72 additions and 19 deletions

14
Cargo.lock generated
View File

@@ -416,12 +416,20 @@ version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "670fdfda89751bc4a84ac13eaa63e205cf0fd22b4c9a5fbfa085b63c1f1d3a30"
[[package]]
name = "memo-map"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "38d1115007560874e373613744c6fba374c17688327a71c1476d1a5954cc857b"
[[package]]
name = "minijinja"
version = "2.14.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "12ea9ac0a51fb5112607099560fdf0f90366ab088a2a9e6e8ae176794e9806aa"
dependencies = [
"memo-map",
"self_cell",
"serde",
]
@@ -511,6 +519,12 @@ dependencies = [
"windows-sys",
]
[[package]]
name = "self_cell"
version = "1.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "16c2f82143577edb4921b71ede051dac62ca3c16084e918bf7b40c96ae10eb33"
[[package]]
name = "serde"
version = "1.0.228"

View File

@@ -11,7 +11,7 @@ bytes = "1.11.0"
http-body-util = "0.1.3"
hyper = { version = "1.8.1", features = ["http1", "http2", "server"] }
macro_rules_attribute = "0.2.2"
minijinja = { version = "2.14.0", features = ["loop_controls"] }
minijinja = { version = "2.14.0", features = ["loop_controls", "loader"] }
serde = { version = "1.0.228", features = ["derive"] }
smol = "2.0.2"
smol-hyper = "0.1.1"

View File

@@ -1,4 +1,5 @@
use std::future::IntoFuture;
use std::sync::Arc;
use crate::AppState;
use anyhow::anyhow;
@@ -11,8 +12,8 @@ use smol::{
use toml::Table;
pub struct Page {
header: Header,
content: String,
pub header: Header,
// content: String,
}
#[derive(Deserialize, Debug)]
@@ -26,13 +27,13 @@ pub enum PageType {
Base,
}
#[derive(Deserialize, Debug)]
#[derive(Deserialize, Debug, Clone)]
pub struct Header {
id: String,
pub id: String,
// r#type: PageType,
r#type: String,
title: Option<String>,
path: Option<String>,
pub path: Option<String>,
// TODO impl this later
// extras: Table,
}
@@ -41,8 +42,8 @@ pub struct Root {
id: String,
// r#type: PageType,
r#type: String,
title: Option<String>,
path: Option<String>,
pub title: Option<String>,
pub path: Option<String>,
// TODO impl this later
// extras: Table,
}
@@ -61,6 +62,25 @@ impl AppState<'_> {
if entry.file_type().await?.is_dir() {
let entry_opened = fs::read_dir(entry.path()).await?;
println!("Opened {}", entry.file_name().to_str().unwrap());
let mut config_path = entry.path();
config_path.push("config.toml");
let config_file = fs::read_to_string(config_path).await?;
let header: Header = toml::from_str(&config_file)?;
let mut index = entry.path();
index.push("index.html");
if let Ok(mreoww) = fs::read_to_string(index).await {
self.env.add_template_owned(header.id.clone(), mreoww)?;
} else {
println!(
"{}, doesn't have a index.html ??",
entry.file_name().to_str().unwrap()
);
continue;
}
let page = Page { header: header };
self.pages.push(page);
} else {
println!("Not parsing {}", entry.file_name().to_str().unwrap());
}

View File

@@ -20,7 +20,7 @@ mod loader;
use crate::loader::*;
struct AppState<'a> {
pages: Vec<Page>,
pub pages: Vec<Page>,
env: Environment<'a>,
}
@@ -28,18 +28,29 @@ struct AppState<'a> {
async fn serve(req: Request<Incoming>, state: Arc<AppState<'_>>) -> Result<Response<Full<Bytes>>> {
println!("Serving {}", req.uri());
let tmpl = state.env.get_template("hello").unwrap();
let guh = tmpl.render(context!(name => "meowmeowmeowmeow!")).unwrap();
let guh2 = state.env.get_template("meow").unwrap();
let guh3 = guh2.render(context!(meow => "meow")).unwrap();
let path = req.uri().path();
let reply: Bytes = match path {
"/" => guh.into(),
"/mreow" => guh3.into(),
_ => "Invalid path!".into(),
let mreow = state.pages.iter().find(|&x| {
if let Some(path_x) = &x.header.path {
println!("{},{}", path_x, path);
if path_x == path {
true
} else {
false
}
} else {
false
}
});
let reply = match mreow {
Some(x) => state
.env
.get_template(&x.header.id)
.unwrap()
.render(context! {})
.unwrap(),
None => "?".to_string(),
};
Ok(Response::new(Full::new(reply)))
Ok(Response::new(Full::new(reply.into())))
}
async fn handle_client(client: Async<TcpStream>, state: Arc<AppState<'_>>) -> Result<()> {

View File

@@ -0,0 +1,3 @@
id = "meowOne"
type = "Root"
path = "/"

View File

@@ -0,0 +1 @@
MREOW

View File

@@ -0,0 +1,3 @@
id = "meow"
type = "Root"
path = "/2"

View File

@@ -0,0 +1 @@
MREOW2