Compare commits

..

12 Commits

Author SHA1 Message Date
3ac59f65f2 Changed current music 2026-01-18 13:31:03 +01:00
4a25c377c4 Added an "ip" page 2025-11-28 22:44:09 +01:00
8c64c5dbe3 Added style for music 2025-11-24 21:22:44 +01:00
88abbe8c14 Added music route to main 2025-11-24 21:22:34 +01:00
c5b85bc359 Added link to music to navbar 2025-11-24 21:22:17 +01:00
8a27a74e9f Created page music 2025-11-24 21:21:56 +01:00
425bac6776 Added iframe html element 2025-11-24 21:21:36 +01:00
5c456fd5cd Formatted file 2025-11-24 21:21:19 +01:00
08b5932cf8 Added robots.txt 2025-11-13 14:31:56 +01:00
c7377e06e3 Added robots.txt (to be verified working) 2025-11-06 11:08:27 +01:00
4e53f9ed1f Added database for projects 2025-10-27 14:28:37 +01:00
d692bf1cdd Changed config file to an example to be able to use local dev file 2025-10-27 09:00:52 +01:00
15 changed files with 420 additions and 50 deletions

1
.gitignore vendored
View File

@@ -2,3 +2,4 @@
.idea
Cargo.lock
.env
config.toml

View File

@@ -8,6 +8,6 @@ actix-web = {version = "4.11.0"}
serde = "1.0.228"
serde_json = "1.0.145"
toml = "0.9.7"
sqlx = {version = "0.8.6", features = ["postgres"]}
sqlx = {version = "0.8.6", features = ["postgres", "runtime-tokio"]}
futures-util = "0.3.31"
clap = { version = "4.5.50", features = ["derive"] }

13
assets/css/ip.css Normal file
View File

@@ -0,0 +1,13 @@
.ip {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.ip h1 {
font-family: 'Indie Flower', cursive;
font-size: 60px;
text-align: center;
color: var(--clr-primary-a60);
}

58
assets/css/music.css Normal file
View File

@@ -0,0 +1,58 @@
.featured {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding: 16px;
}
.featured h1 {
font-size: 48px;
text-align: center;
font-family: 'Indie Flower', cursive;
color: var(--clr-primary-a60);
max-width: 75vw;
}
.featured iframe {
width: 55vw;
height: 100%;
aspect-ratio: 16 / 9;
border: none;
filter: drop-shadow(0px 0px 12px rgba(0, 0, 0, 0.75));
}
.playlist {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding: 16px;
}
.playlist h1 {
font-size: 40px;
text-align: center;
font-family: 'Indie Flower', cursive;
color: var(--clr-primary-a60);
max-width: 75vw;
}
.playlist iframe {
width: 55vw;
height: 100%;
aspect-ratio: 16 / 9;
border: none;
filter: drop-shadow(0px 0px 12px rgba(0, 0, 0, 0.75));
}
@media (width <= 1250px) {
.featured iframe {
width: 90vw;
}
.playlist iframe {
width: 90vw;
}
}

View File

@@ -0,0 +1,13 @@
CREATE TABLE IF NOT EXISTS Projects (
"id" TEXT NOT NULL,
"title" TEXT NOT NULL,
"description" TEXT NOT NULL
);
CREATE TABLE IF NOT EXISTS Project_Detail (
"id" TEXT PRIMARY KEY NOT NULL,
"title" TEXT NOT NULL,
"git_url" TEXT NOT NULL,
"git_title" TEXT NOT NULL,
"description" TEXT NOT NULL
)

View File

@@ -0,0 +1,13 @@
INSERT INTO Projects ("id", "title", "description") VALUES (
'website',
'website',
'This project is the website you currently are on.'
);
INSERT INTO Project_Detail ("id", "title", "git_url", "git_title", "description") VALUES (
'website',
'website',
'https://git.aindustries.be/AINDUSTRIES/aindustries.be',
'aindustries-be',
'This project, the website you are on, is made in Rust such that all the pages are generated by code. <br> That is that each html element is represented by a struct which implements the Render trait (as in render the element to html). <br> As it is right now the system is not that impressive but I believe it can do amazing things in the future.'
)

View File

@@ -390,3 +390,115 @@ impl AnchorBuilder {
}
}
}
pub(crate) struct Iframe {
id: String,
classes: Vec<String>,
src: String,
title: String,
width: usize,
height: usize,
}
impl Render for Iframe {
fn render(&self) -> String {
let classes = self.classes.join(" ");
format!(
"<iframe id=\"{}\" classes=\"{}\" title=\"{}\" width=\"{}\" height=\"{}\" src=\"{}\"></iframe>",
self.id, classes, self.title, self.width, self.height, self.src
)
}
}
pub(crate) struct IframeBuilder {
id: Option<String>,
classes: Option<Vec<String>>,
src: Option<String>,
title: Option<String>,
width: Option<usize>,
height: Option<usize>,
}
impl IframeBuilder {
pub(crate) fn new() -> Self {
Self {
id: None,
classes: None,
src: None,
title: None,
width: None,
height: None,
}
}
pub(crate) fn id<T>(self, id: T) -> Self
where
T: Into<String>,
{
Self {
id: Some(id.into()),
..self
}
}
pub(crate) fn classes<T>(self, classes: Vec<T>) -> Self
where
T: Into<String>,
{
Self {
classes: Some(classes.into_iter().map(|x| x.into()).collect()),
..self
}
}
pub(crate) fn src<T>(self, src: T) -> Self
where
T: Into<String>,
{
Self {
src: Some(src.into()),
..self
}
}
pub(crate) fn title<T>(self, title: T) -> Self
where
T: Into<String>,
{
Self {
title: Some(title.into()),
..self
}
}
pub(crate) fn width(self, width: usize) -> Self {
Self {
width: Some(width),
..self
}
}
pub(crate) fn height(self, height: usize) -> Self {
Self {
height: Some(height),
..self
}
}
pub(crate) fn build(self) -> Iframe {
let id = self.id.unwrap_or(String::new());
let classes = self.classes.unwrap_or(Vec::new());
let title = self.title.unwrap_or(String::new());
let width = self.width.unwrap_or(0);
let height = self.height.unwrap_or(0);
let src = self.src.unwrap_or(String::new());
Iframe {
id,
title,
classes,
width,
height,
src,
}
}
}

View File

@@ -175,9 +175,15 @@ impl BasePageBuilder {
.href("/projects")
.text("Projects")
.build();
let music = Anchor::builder()
.id("music")
.classes(vec!["nav-button"])
.href("/music")
.text("Music")
.build();
let buttons = Division::builder()
.classes(vec!["nav-buttons"])
.elements(boxed_vec![home, projects])
.elements(boxed_vec![home, projects, music])
.build();
let header = Division::builder()
.id("header")

View File

@@ -11,10 +11,13 @@ use std::io::Read;
use std::process::exit;
use toml::from_slice;
use crate::pages::files::robots;
use middleware::MimeType;
use pages::{
files::file,
index,
ip::ip,
music::music,
projects::{project, projects},
};
@@ -99,20 +102,26 @@ async fn main() {
let assets = assets.replace("~", "/home/conta/Code/aindustries.be/assets");
let data = web::Data::new(AppState { assets, pool });
if let Ok(server) = HttpServer::new(move || {
App::new().app_data(data.clone()).service(file).service(
web::scope("")
.wrap(MimeType::new("text/html"))
.service(index)
.service(projects)
.service(project),
)
App::new()
.app_data(data.clone())
.service(file)
.service(robots)
.service(
web::scope("")
.wrap(MimeType::new("text/html"))
.service(index)
.service(projects)
.service(project)
.service(music)
.service(ip),
)
})
.bind(bind_address)
{
match server.run().await {
Ok(_) => {}
Err(e) => {
eprintln!("An error occurred: {e}");
println!("An error occurred: {e}");
}
}
}

View File

@@ -17,3 +17,10 @@ async fn file(file: Path<(String, String)>, data: web::Data<AppState>) -> impl R
};
HttpResponse::Ok().body(bytes)
}
#[get("/robots.txt")]
async fn robots() -> impl Responder {
"User-agent: *\n\
Disallow: /\n\
Allow: /$"
}

34
src/pages/ip.rs Normal file
View File

@@ -0,0 +1,34 @@
use crate::html::elements::{Heading, Link};
use crate::html::layouts::Division;
use crate::html::pages::BasePage;
use crate::html::{Render, boxed_vec};
use actix_web::HttpRequest;
use actix_web::{Responder, get};
#[get("/ip")]
async fn ip(request: HttpRequest) -> impl Responder {
let info = request.connection_info();
let ip = info.realip_remote_addr();
let text = Heading::builder()
.text(format!(
"Your IP address is {}<br>Don't ask how I know.",
ip.unwrap_or("?")
))
.build();
let div = Division::builder()
.classes(vec!["ip"])
.elements(boxed_vec![text])
.build();
let css = Link::builder()
.rel("stylesheet")
.href("/static/css/ip.css")
.build();
BasePage::builder()
.title("Your IP address")
.head(boxed_vec![css])
.body(boxed_vec![div])
.build()
.render()
}

View File

@@ -1,4 +1,6 @@
pub(crate) mod files;
pub(crate) mod ip;
pub(crate) mod music;
pub(crate) mod projects;
use crate::html::elements::{Heading, Link};

54
src/pages/music.rs Normal file
View File

@@ -0,0 +1,54 @@
use crate::html::layouts::DivisionBuilder;
use crate::html::pages::BasePageBuilder;
use crate::html::{Render, boxed_vec};
use crate::AppState;
use crate::html::elements::{HeadingBuilder, IframeBuilder, Link};
use actix_web::web::Data;
use actix_web::{Responder, get, web};
use sqlx::query_as;
#[get("/music")]
async fn music(state: Data<AppState>) -> impl Responder {
let featured_title = HeadingBuilder::new()
.level(1)
.text("The song I've been listening to the most recently is \"Shiawase - VIP\" by Dion Timmer.")
.build();
let featured_iframe = IframeBuilder::new()
.src("https://www.youtube.com/embed/suisIF4hwyw")
.build();
let featured = DivisionBuilder::new()
.classes(vec!["featured"])
.id("featured")
.elements(boxed_vec![featured_title, featured_iframe])
.build();
let playlist_title = HeadingBuilder::new()
.text(
"You can find below my primary playlist, \
the one containing almost all the songs I have been listening to throughout the years.",
)
.build();
let playlist_iframe = IframeBuilder::new()
.src(
"https://open.spotify.com/embed/playlist/\
3owjyc1RILDGkgCmdCal39?utm_source=generator",
)
.build();
let playlist = DivisionBuilder::new()
.id("playlist")
.classes(vec!["playlist"])
.elements(boxed_vec![playlist_title, playlist_iframe])
.build();
let css = Link::builder()
.rel("stylesheet")
.href("/static/css/music.css")
.build();
let page = BasePageBuilder::new()
.title("Music")
.head(boxed_vec![css])
.body(boxed_vec![featured, playlist])
.build();
page.render()
}

View File

@@ -1,11 +1,22 @@
use crate::AppState;
use crate::html::elements::{Anchor, Heading, Link, Paragraph};
use crate::html::layouts::Division;
use crate::html::pages::BasePage;
use crate::html::{Render, boxed_vec};
use actix_web::web::Data;
use actix_web::{Responder, get, web};
use serde::Deserialize;
use sqlx::query_as;
#[derive(Deserialize)]
struct Project {
id: String,
title: String,
description: String,
}
#[get("/projects")]
async fn projects() -> impl Responder {
async fn projects(app_state: Data<AppState>) -> impl Responder {
let title = Heading::builder().text("My projects").build();
let desc = Heading::builder()
.level(2)
@@ -14,37 +25,64 @@ async fn projects() -> impl Responder {
(I've done a lot of small projects but they are not worth it.)",
)
.build();
let website_title = Heading::builder().text("Website").build();
let website_desc = Paragraph::builder()
.classes(vec!["project-desc"])
.text("This project is the website you currently are on.")
.build();
let view = Anchor::builder()
.classes(vec!["project-view"])
.href("/projects/website")
.text("Learn More")
.build();
let info = Division::builder()
.classes(vec!["project-info"])
.elements(boxed_vec![website_desc, view])
.build();
let website = Division::builder()
.classes(vec!["project"])
.elements(boxed_vec![website_title, info])
.build();
let projects = match query_as!(Project, "SELECT id, title, description FROM Projects")
.fetch_all(&app_state.pool)
.await
{
Ok(projects) => projects,
Err(_) => {
vec![]
}
};
let items: Vec<Box<dyn Render>> = projects
.into_iter()
.map(|p| {
let title = Heading::builder().text(p.title).build();
let description = Paragraph::builder()
.classes(vec!["project-desc"])
.text(p.description)
.build();
let view = Anchor::builder()
.classes(vec!["project-view"])
.href(format!("/projects/{}", p.id))
.text("Learn More")
.build();
let info = Division::builder()
.classes(vec!["project-info"])
.elements(boxed_vec![description, view])
.build();
Box::new(
Division::builder()
.classes(vec!["project"])
.elements(boxed_vec![title, info])
.build(),
) as Box<dyn Render>
})
.collect();
let css = Link::builder()
.rel("stylesheet")
.href("/static/css/projects.css")
.build();
let mut body = boxed_vec![title, desc];
body.extend(items);
let page = BasePage::builder()
.title("Projects")
.head(boxed_vec![css])
.body(boxed_vec![title, desc, website])
.body(body)
.build();
page.render()
}
#[derive(Deserialize)]
struct ProjectDetail {
id: String,
title: String,
git_url: String,
git_title: String,
description: String,
}
#[get("/projects/{project}")]
async fn project(project: web::Path<String>) -> impl Responder {
async fn project(project: web::Path<String>, app_state: Data<AppState>) -> impl Responder {
let project = project.into_inner();
let css = Link::builder()
.rel("stylesheet")
@@ -54,25 +92,35 @@ async fn project(project: web::Path<String>) -> impl Responder {
.title(format!("Project-{}", project))
.head(boxed_vec![css])
.build();
match project.as_str() {
"website" => {
let title = Heading::builder().text("Website").build();
let gitea = Anchor::builder()
.href("https://git.aindustries.be/AINDUSTRIES/aindustries.be")
.text("aindustries-be")
.build();
let desc = Paragraph::builder().classes(vec!["description"]).text(
format!("This project, the website you are on, \
is made in Rust such that all the pages are generated by code.<br>\
That is that each html element is represented by a struct which implements the Render trait (as in render the element to html).<br>\
As it is right now the system is not that impressive but I believe it can do amazing things in the futur.<br>\
<br>\
Wish to see more? Check out the gitea repository: {}", gitea.render()),
).build();
page.append_element_to_body(title);
page.append_element_to_body(desc);
let project = match query_as!(
ProjectDetail,
"SELECT * FROM Project_Detail WHERE id = $1",
project
)
.fetch_one(&app_state.pool)
.await
{
Ok(project) => project,
Err(error) => {
// return not found page
eprintln!("Error fetching project: {:?}", error);
return page.render();
}
_ => {}
}
};
let title = Heading::builder().text(project.title).build();
let gitea = Anchor::builder()
.href(project.git_url)
.text(project.git_title)
.build();
let desc = Paragraph::builder()
.classes(vec!["description"])
.text(format!(
"{}<br><br> Wish to see more? Check out the gitea repository: {}",
project.description,
gitea.render()
))
.build();
page.append_element_to_body(title);
page.append_element_to_body(desc);
page.render()
}