From 4b108325914be1952ae72eb15bc4c546b6d3ecb1 Mon Sep 17 00:00:00 2001 From: AINDUSTRIES Date: Sun, 5 Oct 2025 23:29:11 +0200 Subject: [PATCH] Added main page and static files --- src/pages/files.rs | 19 +++++++++++++++++++ src/pages/mod.rs | 45 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 src/pages/files.rs create mode 100644 src/pages/mod.rs diff --git a/src/pages/files.rs b/src/pages/files.rs new file mode 100644 index 0000000..7eb8939 --- /dev/null +++ b/src/pages/files.rs @@ -0,0 +1,19 @@ +use actix_web::web::Path; +use actix_web::{HttpResponse, Responder, get}; +use std::fs::File; +use std::io::Read; +use std::path::PathBuf; + +#[get("/static/{file_type}/{file_name}")] +async fn file(file: Path<(String, String)>) -> impl Responder { + //TODO use assets dir + let mut path = PathBuf::from("assets"); + path.push(&file.0.replace("/", "")); + path.push(&file.1.replace("/", "")); + let mut file = File::open(path).unwrap(); + let mut bytes = Vec::new(); + if file.read_to_end(&mut bytes).is_err() { + return HttpResponse::NotFound().body("File not found"); + }; + HttpResponse::Ok().body(bytes) +} diff --git a/src/pages/mod.rs b/src/pages/mod.rs new file mode 100644 index 0000000..0991ec1 --- /dev/null +++ b/src/pages/mod.rs @@ -0,0 +1,45 @@ +pub(crate) mod files; + +use crate::html::elements::{a, div, h1, h2, img, link, p}; +use crate::html::{Page, Render}; +use actix_web::http::header::ContentType; +use actix_web::mime::TEXT_HTML; +use actix_web::{HttpResponse, Responder, get}; + +#[get("/")] +async fn index() -> impl Responder { + let mut page = Page::new("AINDUSTRIES".to_string()); + // header + let mut header = div::new("header".to_string(), vec!["header".to_string()]); + let name = p::new("name".to_string(), vec!["name".to_string()], "AINDUSTRIES".to_string()); + let mut buttons = div::new("buttons".to_string(), vec!["nav-buttons".to_string()]); + let home = a::new("home".to_string(), vec!["nav-button".to_string()], "/".to_string(), "Home".to_string()); + buttons.append_element(home); + header.append_element(name); + header.append_element(buttons); + // background + let image = img::new("background".to_string(), vec!["background".to_string()], "static/img/background.png".to_string()); + // introduction + let mut intro = div::new("intro".to_string(), vec!["intro".to_string()]); + let hi = h1::new("Hello and welcome!".to_string()); + let detail = h2::new("This here is a small website to show the passion I have for computers.
\ + I have always had a good time creating and discovering new things.
\ + Your may discover some of my projects here on this showcase.".to_string()); + let note = p::new("note".to_string(), vec!["note".to_string()], "Website in construction.".to_string()); + intro.append_element(hi); + intro.append_element(detail); + intro.append_element(note); + // css + let base = link::new("stylesheet".to_string(), "static/css/base.css".to_string()); + let index = link::new("stylesheet".to_string(), "static/css/index.css".to_string()); + // add elements to the page in order + page.append_element_to_head(base); + page.append_element_to_head(index); + page.append_element_to_body(image); + page.append_element_to_body(header); + page.append_element_to_body(intro); + let response = HttpResponse::Ok() + .insert_header(ContentType(TEXT_HTML)) + .body(page.render()); + response +}