diff --git a/config.default.toml b/config.default.toml index 738e0a1..a90db31 100644 --- a/config.default.toml +++ b/config.default.toml @@ -5,4 +5,8 @@ host="0.0.0.0" port=8080 [database] -url="postgresql://postgres@localhost/mctest" \ No newline at end of file +url="postgresql://postgres@localhost/mctest" + +[[redirect]] +from="hmm" +to="https://stallman-copypasta.github.io/" \ No newline at end of file diff --git a/src/config/definition.rs b/src/config/definition.rs index 9568273..16cd269 100644 --- a/src/config/definition.rs +++ b/src/config/definition.rs @@ -1,19 +1,26 @@ use serde::Deserialize; -#[derive(Debug, Deserialize)] +#[derive(Debug, Deserialize, Clone)] pub struct Config { pub debug: bool, pub webserver: ConfigWebserver, - pub database: ConfigDatabase + pub database: ConfigDatabase, + pub redirect: Vec } -#[derive(Debug, Deserialize)] +#[derive(Debug, Deserialize, Clone)] pub struct ConfigWebserver { pub host: String, pub port: u16, } -#[derive(Debug, Deserialize)] +#[derive(Debug, Deserialize, Clone)] pub struct ConfigDatabase { pub url: String, +} + +#[derive(Debug, Deserialize, Clone)] +pub struct ConfigRedirect { + pub from: String, + pub to: String, } \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 9be5c63..b5163ab 100644 --- a/src/main.rs +++ b/src/main.rs @@ -26,7 +26,7 @@ async fn main() -> anyhow::Result<()> { return Ok(()); } - if let Err(e) = web::start_actix(config.get_ref(), database).await { + if let Err(e) = web::start_actix(config.get_ref().clone(), database).await { log::error!("Actix had an error: {e}"); } Ok(()) diff --git a/src/web/mod.rs b/src/web/mod.rs index ea9ccec..259fc7f 100644 --- a/src/web/mod.rs +++ b/src/web/mod.rs @@ -8,7 +8,7 @@ use actix_files as actix_fs; use crate::{config::definition::Config, database::Database}; -pub(crate) async fn start_actix(config: &Config, database: Database) -> anyhow::Result<()> { +pub(crate) async fn start_actix(config: Config, database: Database) -> anyhow::Result<()> { let bindip = format!("{}:{}", config.webserver.host, config.webserver.port); log::info!("Serving an http server at http://{bindip}"); @@ -16,7 +16,10 @@ pub(crate) async fn start_actix(config: &Config, database: Database) -> anyhow:: App::new() .app_data(actix_web::web::Data::new(Mutex::new(database.clone()))) .route("/", web::get().to(routes::index)) // index.html + .route("/projects", web::get().to(routes::projects::projects)) // index.html + .route("/contact", web::get().to(routes::contact::contact)) // index.html .service(routes::api::get_scope()) + .service(routes::redirect::get_scope(&config)) .service(actix_fs::Files::new("/static", "./static").index_file("index.html")) // static directory .service(web::redirect("/favicon.ico", "/static/favicon.ico")) //? special redirect for favicon }) diff --git a/src/web/routes/contact.rs b/src/web/routes/contact.rs new file mode 100644 index 0000000..6427e11 --- /dev/null +++ b/src/web/routes/contact.rs @@ -0,0 +1,19 @@ + +use std::sync::Mutex; + +use actix_web_lab::respond::Html; +use actix_web::{web::Data, Responder, Result}; +use askama::Template; + +use crate::{database::Database, web::templates::ContactTemplate}; + + + +pub async fn contact(_: Data>) -> Result { + + let html = ContactTemplate { + title: String::from("MCorange - Contact me!"), + }.render().expect("Failed to render contacts.html"); + + Ok(Html(html)) +} \ No newline at end of file diff --git a/src/web/routes/mod.rs b/src/web/routes/mod.rs index 7c8d702..57a9154 100644 --- a/src/web/routes/mod.rs +++ b/src/web/routes/mod.rs @@ -1,4 +1,7 @@ pub mod api; +pub mod contact; +pub mod projects; +pub mod redirect; use std::sync::Mutex; @@ -15,24 +18,13 @@ pub async fn index(db: Data>) -> Result { let posts = match crate::database::models::posts::Post::get_last_n(&mut db.lock().unwrap(), 10).await { Ok(p) => p, - _ => { - vec![] - } + _ => vec![] }; let html = IndexTemplate { posts, - title: String::from("Very cool mcoranges website :3"), + title: String::from("MCorange - The website :3"), }.render().expect("Failed to render index.html"); Ok(Html(html)) -} -/* -
- post img - -

Title text

-

Description text

-
-
-*/ \ No newline at end of file +} \ No newline at end of file diff --git a/src/web/routes/projects.rs b/src/web/routes/projects.rs new file mode 100644 index 0000000..3a741a3 --- /dev/null +++ b/src/web/routes/projects.rs @@ -0,0 +1,19 @@ + +use std::sync::Mutex; + +use actix_web_lab::respond::Html; +use actix_web::{web::Data, Responder, Result}; +use askama::Template; + +use crate::{database::Database, web::templates::ProjectTemplate}; + + + +pub async fn projects(_: Data>) -> Result { + + let html = ProjectTemplate { + title: String::from("MCorange - My projects :O"), + }.render().expect("Failed to render projects.html"); + + Ok(Html(html)) +} \ No newline at end of file diff --git a/src/web/routes/redirect.rs b/src/web/routes/redirect.rs new file mode 100644 index 0000000..55d4f11 --- /dev/null +++ b/src/web/routes/redirect.rs @@ -0,0 +1,16 @@ +use actix_web::{web::{self, redirect}, HttpResponse, Scope}; + +use crate::config::definition::Config; + +pub fn get_scope(config: &Config) -> Scope { + let mut s = Scope::new("/r") + .route("/", web::get().to(HttpResponse::Ok)); + + for r in config.redirect.clone() { + s = s.service(redirect(r.from, r.to)); + } + // .service( + // webhooks::get_scope() + // ) + s +} \ No newline at end of file diff --git a/src/web/templates.rs b/src/web/templates.rs index a17aec2..a3b9078 100644 --- a/src/web/templates.rs +++ b/src/web/templates.rs @@ -10,3 +10,16 @@ pub struct IndexTemplate{ } +#[derive(Debug, Clone, Template)] +#[template(path = "projects.html")] +pub struct ProjectTemplate{ + pub title: String, +} + +#[derive(Debug, Clone, Template)] +#[template(path = "contact.html")] +pub struct ContactTemplate{ + pub title: String, +} + + diff --git a/static/css/contact.css b/static/css/contact.css new file mode 100644 index 0000000..e69de29 diff --git a/static/css/projects.css b/static/css/projects.css new file mode 100644 index 0000000..e69de29 diff --git a/templates/contact.html b/templates/contact.html new file mode 100644 index 0000000..2afce3a --- /dev/null +++ b/templates/contact.html @@ -0,0 +1,61 @@ + + + + {{title}} + + + + + + +
+
+

{{title}}

+
+
+
+ Home + Projects + Contact me + ??? + +
+
+

Nothing here, for now

+
+
+
+ +
+
+ +

login

+

secrets beyond human comprehension lie beneath this unassuming login screen

+ +
+
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ +
+ +
+ + + + diff --git a/templates/index.html b/templates/index.html index bb0a3f0..8137ae8 100644 --- a/templates/index.html +++ b/templates/index.html @@ -14,10 +14,10 @@
- Home - Home - Home - Home + Home + Projects + Contact me + ???
diff --git a/templates/panel.html b/templates/panel.html new file mode 100644 index 0000000..aeaedf0 --- /dev/null +++ b/templates/panel.html @@ -0,0 +1,13 @@ + + + + {{title}} + + + + + +

Nothing in here, for now.

+ + + diff --git a/templates/projects.html b/templates/projects.html new file mode 100644 index 0000000..bb12fa8 --- /dev/null +++ b/templates/projects.html @@ -0,0 +1,61 @@ + + + + {{title}} + + + + + + +
+
+

{{title}}

+
+
+
+ Home + Projects + Contact me + ??? + +
+
+

Nothing here, for now

+
+
+
+ +
+
+ +

login

+

secrets beyond human comprehension lie beneath this unassuming login screen

+ +
+
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ +
+ +
+ + + +